页面缓存后,TYPO3搜索框不起作用

时间:2018-01-17 20:28:34

标签: caching typo3 extbase

TYPO3中的缓存存在问题。 我有一个简单的搜索框,它调用itemRepository来根据搜索词获取一些项目。如果没有给出任何条款,则列出所有项目。

这仅适用于第一次。 点击搜索按钮后,搜索词将被缓存,即使我输入新的搜索词,也会一直使用。 第一个术语始终显示在搜索框中并用于搜索。我必须清除缓存以使其再次工作。

即使我把var_dump($terms);放在哪里,它也会产生一次输出。

我知道我可以为listAction禁用缓存,但这会使页面非常慢,因为默认情况下会列出很多项目。 这有解决方案吗?使用TYPO3 8.7.8。

<!-- Searchbox -->
<f:form name="list" action="list" enctype="multipart/form-data">
    <f:form.textfield name="terms" value="{terms}" placeholder="{f:translate(key:'enter_searchterm')}"/>
    <button><f:translate key="search"/></button>
</f:form>

<!-- list with found items -->
<f:for each="{items}" as="item">

    ...
    ...

    <li>{item.title}</li>

    ...
    ...

</f:for>





/**
* @param string $terms
*/
public function listAction($terms = "") {
    $items = $this->itemRepository->findBySearch($terms);

    $this->view->assign('items', $items);
    $this->view->assign('terms', $terms);
}

2 个答案:

答案 0 :(得分:1)

您需要在list文件的non-cacheable列表中添加ext_localconf.php操作。

// non-cacheable actions
[
    'Controller' => 'list',
]

答案 1 :(得分:0)

您确实应该将list() - 具有搜索字词参数的操作设置为不可缓存的。

要保持未过滤列表的性能,您可以添加另一个非缓存操作(不带任何参数)。

通过这种方式,您可以将性能保留在未过滤的列表中。