php - TYPO3 9.5 - 我的扩展中的 QuerieResult 缓存 - 函数 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
(仅在获取时,设置工作正常)
解决方案
您不能缓存此类,因为这意味着对其进行序列化,并且该类包含阻止某些属性包含在序列化字符串中的显式方法。事实上,唯一包含的属性是(query
导致结果的输入查询)。
您可能能够缓存 QueryResult,然后手动调用注入方法来添加 DataMapper 等实例 - 但即使您这样做了,序列化的 QueryResult 也不会包含结果,并且每次您尝试从中加载实体时都会再次触发它。
正确的方法是提取到您知道将允许序列化结果的非 QueryResult(数组,自己选择的迭代器)。
推荐阅读
- asynchronous - 如何在 Erlang 中进行并行调用并等待所有结果?
- mongodb - 在 MongoDB Compass 中查询二进制字段
- scheme - 将“-0”转换为“-0.0”的球拍/方案
- firebase - Nuxt - result.forEach 不是函数?
- java - 什么是静态上下文变量
- oauth - Basecamp 3 API 的令牌 URL 问题
- canvas - 使用 p5.js 仅保存画布的某个区域
- php - 将文本字段中的条目放入 mysql 数据库
- xcode - 无法保存文件“File.scn”
- javascript - 我怎样才能制作一个不和谐的机器人来做这样的事情?