[英]TYPO3 9.5 Extbase plugin cache implementation
I am trying to get a cache working in my plugin. 我正在尝试在插件中使用缓存。 In ext_localconf.php
在ext_localconf.php中
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension'] = [];}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['frontend'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend';}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['options'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['options'] = ['defaultLifetime' => 0];}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['groups'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['groups'] = ['pages'];}
In my controller action : 在我的控制器动作中:
$cacheIdentifier = 'topic' . $topic->getUid();
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('myextension');
$result = unserialize($cache->get($cacheIdentifier));
if ($result !== false ) {
DebuggerUtility::var_dump($result);
} else {
$result = $this->postRepository->findByTopic($topic->getUid(), $page, $itemsPerPage);
$cache->set($cacheIdentifier, serialize($result), ['tag1', 'tag2']);
DebuggerUtility::var_dump($result);
}
The first time the page with the action gets loaded all is ok and the entry has been made in de database (cf_myextension and cf_myextension_tags}. 第一次加载包含操作的页面就可以了,并且已经在数据库中创建了条目(cf_myextension和cf_myextension_tags}。
But the 2nd time the cache gets loaded and I get an error. 但是第二次缓存被加载,我得到一个错误。 Even
DebuggerUtility::var_dump($result);
甚至
DebuggerUtility::var_dump($result);
does not work: 不起作用:
Call to a member function map() on null
in ../typo3/sysext/extbase/Classes/Persistence/Generic/QueryResult.php line 96
*/
protected function initialize()
{
if (!is_array($this->queryResult)) {
$this->queryResult = $this->dataMapper->map($this->query->getType(), $this->persistenceManager->getObjectDataByQuery($this->query));
}
}
/**
A normal var_dump works and spits out the cache entry. 普通的var_dump可以工作并吐出缓存条目。 What is the problem?
问题是什么? Do I forget something?
我会忘记什么吗? Can't a QueryResult together with some other variables not be stored as an array in the cache?
不能将QueryResult和其他一些变量一起存储为数组吗? I also tried VariableFrontend cache, which produced the same error.
我还尝试了VariableFrontend缓存,该缓存产生了相同的错误。
The E-tools GUI application indents and pretty formats HTML, JavaScript, JSON and SQL. E-tools GUI应用程序缩进并以漂亮的格式显示HTML,JavaScript,JSON和SQL。 To install the e-tools snap package in all currently supported versions of Ubuntu open the terminal and type:
要在当前所有受支持的Ubuntu版本中安装e-tools snap软件包,请打开终端并输入:
sudo snap install e-tools
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.