簡體   English   中英

TYPO3 9.5 Extbase插件緩存實現

[英]TYPO3 9.5 Extbase plugin cache implementation

我正在嘗試在插件中使用緩存。 在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緩存,該緩存產生了相同的錯誤。

E-tools GUI應用程序縮進並以漂亮的格式顯示HTML,JavaScript,JSON和SQL。 要在當前所有受支持的Ubuntu版本中安裝e-tools snap軟件包,請打開終端並輸入:

sudo snap install e-tools

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM