[英]TYPO3 9.5 - QuerieResult Caching in my Extension - function map() on null
我正在尝试在插件中使用Produclist缓存。
我的ext_localconf.php
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['product_cache'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['product_cache'] = [];
}
if( !isset($GLOBALS['TYPO3_CONF_VARS'] ['SYS']['caching']['cacheConfigurations']['product_cache']['frontend'] ) ) {
$GLOBALS['TYPO3_CONF_VARS'] ['SYS']['caching']['cacheConfigurations']['product_cache']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend';
}
还有我的控制器
$cache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('product_cache');
if(($products = $cache->get($cacheIdentifier)) === FALSE){
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$productController = $objectManager->get(ProductController::class);
$productController->setSettings($this->settings);
$products = $productController->getEditedProducts($catId);
$cache->set($cacheIdentifier, $products, ['productajax'], 84600);
}
正常的内容(例如字符串,int或数组)可以正常工作,但是当我尝试使用DatabaseResultquerie进行尝试而不是系统崩溃时出现此错误: Call to a member function map() on null
(仅在获取时,设置才能正常使用)
您不能缓存此类,因为这意味着对其进行序列化,并且该类包含显式方法,这些方法可防止某些属性包含在序列化的字符串中。 事实上, 所包含的唯一属性,是query
(导致该结果的输入查询)。
您可能可以缓存QueryResult,然后手动调用注入方法以添加DataMapper等的实例。但是,即使这样做,序列化的QueryResult也不会包含结果,并且每次您尝试从中加载实体时都会再次触发它。
正确的方法是将一个已知的非提取结果(数组,自己选择的迭代器)提取到允许序列化结果的位置。
参见: https : //github.com/TYPO3/TYPO3.CMS/blob/v8.7.26/typo3/sysext/extbase/Classes/Persistence/Generic/QueryResult.php#L250
如果是Ajax-Controller,则可能要缓存生成的JSON响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.