TYPO3 9.5 - 我的扩展中的 QuerieResult 缓存 - 函数 map() on null
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);
}
像字符串、整数或数组这样的普通内容工作正常,但是当我用 DatabaseResultquerie 尝试这个时,系统崩溃并出现以下错误:Call to a member function map() on null
(仅在获取时有效,设置正常)
您不能缓存此 class,因为这意味着对其进行序列化,并且 class 包含阻止某些属性包含在序列化字符串中的显式方法。事实上, 包含的唯一 属性 是 query
(导致结果的输入查询)。
您可以缓存 QueryResult,然后手动调用注入方法来添加 DataMapper 等实例 - 但即使您这样做,序列化的 QueryResult 也不会包含结果,并且会在您每次尝试时再次触发从中加载一个实体。
正确的方法是提取到您知道可以序列化结果的 not-QueryResult(数组,自己选择的迭代器)。
如果这是 Ajax-Controller,您可能希望缓存生成的 JSON 响应。
我正在尝试让 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);
}
像字符串、整数或数组这样的普通内容工作正常,但是当我用 DatabaseResultquerie 尝试这个时,系统崩溃并出现以下错误:Call to a member function map() on null
(仅在获取时有效,设置正常)
您不能缓存此 class,因为这意味着对其进行序列化,并且 class 包含阻止某些属性包含在序列化字符串中的显式方法。事实上, 包含的唯一 属性 是 query
(导致结果的输入查询)。
您可以缓存 QueryResult,然后手动调用注入方法来添加 DataMapper 等实例 - 但即使您这样做,序列化的 QueryResult 也不会包含结果,并且会在您每次尝试时再次触发从中加载一个实体。
正确的方法是提取到您知道可以序列化结果的 not-QueryResult(数组,自己选择的迭代器)。
如果这是 Ajax-Controller,您可能希望缓存生成的 JSON 响应。