【问题标题】:TYPO3 9.5 - QuerieResult Caching in my Extension - function map() on nullTYPO3 9.5 - 我的扩展中的 QuerieResult 缓存 - 函数 map() on null
【发布时间】:2019-06-06 08:47:56
【问题描述】:

我正在尝试在我的插件中使用 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

(仅在获取时,设置工作正常)

【问题讨论】:

    标签: php caching typo3 extbase typo3-9.x


    【解决方案1】:

    您不能缓存此类,因为这意味着对其进行序列化,并且该类包含显式方法,可防止某些属性包含在序列化字符串中。事实上,包含的唯一属性是query(导致结果的输入查询)。

    您也许可以缓存 QueryResult,然后手动调用注入方法来添加 DataMapper 等实例 - 但即使您这样做了,序列化的 QueryResult 也不会包含结果,并且会在您每次尝试加载时再次触发一个实体。

    正确的方法是提取到一个非 QueryResult(数组,自己选择的迭代器),你知道它会允许结果被序列化。

    见:https://github.com/TYPO3/TYPO3.CMS/blob/v8.7.26/typo3/sysext/extbase/Classes/Persistence/Generic/QueryResult.php#L250

    【讨论】:

      【解决方案2】:

      如果这是一个 Ajax 控制器,您可能希望缓存生成的 JSON 响应。

      【讨论】:

        猜你喜欢
        • 2011-07-15
        • 1970-01-01
        • 2013-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多