使用 PHP,我正在渲染一个看起来像这样的 HTML 表:
--------------------------------------------------
| title    | description         | actions       |
-------------------------------------------------|
| title1   | desc1               | edit / delete |
| title2   | desc2               | edit / delete |
| title3   | desc3               | edit / delete |
| title4   | desc4               | edit / delete |
--------------------------------------------------
代码是这样工作的(精简版!在这个例子中没有thead等tbody):
<table>
  <?php foreach ( $tableData as $row ): ?>
  <tr>
    <!-- Render columns (title, description)
    <?php foreach ( $columnData as $column ): ?>
    <td>
      <?= $row[$column['name']]; ?>
    </td>
    <?php endforeach; ?>
    <!-- Render actions -->
    <?php foreach ( $actions as $action ): ?>
    <td>
      <?= include($action); // include the proper action button! ?>
    </td>
    <? endforeach; ?>
  </tr>
  <?php endforeach; ?>
</table>
这给了我想要的结果。但我只有一个问题。当我有 1000 多条记录时,它会变得有点慢。我已经注意到这是因为我正在include为每个表格行做一个。当我删除include然后一切运行非常快。
该included文件包含一些 PHP 逻辑。所以我不能只做一个file_get_contents. 好吧,我可以,但是我必须用它eval()来解析内容。但我宁愿根本不使用该功能。
所以现在我想知道是否可以以某种方式缓存包含的文件?这样 PHP 就不必一遍又一遍地主动包含实际文件,而是从其缓存中获取它?这样的事情可能吗?
或者有没有更好的选择?