如何在自己的扩展中配置缓存

时间:2013-10-12 15:26:52

标签: typo3 extbase

我想知道如何为我自己的扩展配置coorectly缓存。

到目前为止,我做了以下事情:

ext_localconf.php

if (!is_array($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY])) {
  $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY] = array();
  $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY]['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend';
  $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY]['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend';
  $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY]['options']['compression'] = 1;
}

在我的TestController.php中我写了这个:

$this->cache = $GLOBALS['typo3CacheManager']->getCache(
            $this->request->getControllerExtensionKey()
);

$cacheIdentifier = sha1('form_data_' . $GLOBALS["TSFE"]->id);

$formData = array();


if ($this->cache->has($cacheIdentifier)) { //This always results to false
  $formData = $this->cache->get($cacheIdentifier);
} else {
  $conditions = array(
     path' => $this->settings['httpClient']['baseUrl'] . 'list.xml'
  );

  $formData = $this->TestRepository->getFormData($conditions);
  $this->cache->set($cacheIdentifier,$formData);
}

所以我不知道自己做错了什么。

有人可以指出我正确的方向。

我正在和我一起工作 TYPO3 6.1.5 extbase 6.1.0

1 个答案:

答案 0 :(得分:1)

好的,我找到了答案,因为我检查了TYPO3_CONF_VARS的FLUID Tamplates:

他们有一些不同的缓存配置:

将ext_localconf.php转换为

之后
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY]['frontend'] =
'TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend';
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'][$_EXTKEY]['backend'] =
'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend';

一切正常。