【问题标题】:TYPO3 9.5 Extbase plugin cache implementationTYPO3 9.5 Extbase 插件缓存实现
【发布时间】:2018-11-22 15:12:10
【问题描述】:

我正在尝试在我的插件中使用缓存。 在 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'];}

在我的控制器操作中:

$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);
}

第一次加载该操作的页面一切正常,并且已在数据库中创建条目(cf_myextension 和 cf_myextension_tags}。

但是第二次缓存被加载时,我得到了一个错误。即使DebuggerUtility::var_dump($result); 也不起作用:

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));
    }
}

/**

正常的 var_dump 工作并吐出缓存条目。问题是什么?我忘记了什么吗?不能将 QueryResult 与其他一些变量一起作为数组存储在缓存中吗?我还尝试了 VariableFrontend 缓存,它产生了同样的错误。

【问题讨论】:

    标签: caching typo3 extbase typo3-9.x


    【解决方案1】:

    E-tools GUI 应用程序缩进和格式化 HTML、JavaScript、JSON 和 SQL。要在所有当前支持的 Ubuntu 版本中安装 e-tools snap 包,请打开终端并输入:

    sudo snap install e-tools
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2021-07-19
      相关资源
      最近更新 更多