通过将 cacheManager 迁移到构造函数注入,类不存在

问题描述

我在将 cacheManager 实例迁移到 TYPO3 10 时遇到问题。根据 TYPO3 10 文档,应通过构造函数而不是“cacheManager”实例注入缓存。
我按照文档,yaml 配置也正确,我在前端收到一条错误消息。

"Class TYPO3\CMS\Core\Cache\Frontend\Frontend does not exist. Reflection Failed."

据我所知,这个类根本不存在。
这个错误解决办法吗?

EXT:my_ext/Configuration/Services.yaml

services:
  cache.my_ext:
    class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
    factory: ['@TYPO3\CMS\Core\Cache\CacheManager','getCache']
    arguments: ['my_ext']
  Myvendor\MyExt\Connection\Http:
    arguments:
      $cache: '@cache.my_ext'

EXT:my_ext/Classes/Connection/Http.PHP

    /**
     * @var FrontendInterface
     */
    private $cache;
    public function __construct(FrontendInterface $cache)
    {
        $this->cache = $cache;
    }
    public function initializeObject() {
        $className = explode('\\',get_class($this));
        $this->extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCasetoLowerCaseUnderscored($className[1]);
    }
    public function getDataFromUrl($url,$cachingTags = array()) {
        $cacheIdentifier = sha1($url);
        $remoteData = $this->getUrl($url . "&" . time());
        if (($this->cache->get($cacheIdentifier)) === false) {
            $this->cache->set($cacheIdentifier,$remoteData,$cachingTags,36000);
        }
        return $remoteData;
    }

我遵循了此处的文档:

https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/CachingFramework/Developer/Index.html

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)