升级到Magento 2.4之后,我得到“类configure_block_cache不存在”

问题描述

有问题的错误

1 exception(s):
Exception #0 (ReflectionException): Class configured_block_cache does not exist

Exception #0 (ReflectionException): Class configured_block_cache does not exist
<pre>#1 Magento\Framework\Code\Reader\ClassReader->getConstructor() called at [vendor/magento/framework/ObjectManager/DeFinition/Runtime.PHP:54]
#2 Magento\Framework\ObjectManager\DeFinition\Runtime->getParameters() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:100]
#3 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:150]
#4 Magento\Framework\ObjectManager\Factory\Compiled->get() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:79]
#5 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:150]
#6 Magento\Framework\ObjectManager\Factory\Compiled->get() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:79]
#7 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:150]
#8 Magento\Framework\ObjectManager\Factory\Compiled->get() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:79]
#9 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.PHP:56]
#10 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/View/Result/PageFactory.PHP:56]
#11 Magento\Framework\View\Result\PageFactory->create() called at [vendor/magento/framework/App/View.PHP:74]
#12 Magento\Framework\App\View->__construct() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.PHP:121]
#13 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:108]
#14 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:150]
#15 Magento\Framework\ObjectManager\Factory\Compiled->get() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:79]
#16 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:150]
#17 Magento\Framework\ObjectManager\Factory\Compiled->get() called at [vendor/magento/framework/ObjectManager/Factory/Compiled.PHP:79]
#18 Magento\Framework\ObjectManager\Factory\Compiled->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.PHP:56]
#19 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/App/ActionFactory.PHP:44]
#20 Magento\Framework\App\ActionFactory->create() called at [vendor/magento/framework/App/Router/Base.PHP:306]
#21 Magento\Framework\App\Router\Base->matchAction() called at [vendor/magento/framework/App/Router/Base.PHP:167]
#22 Magento\Framework\App\Router\Base->match() called at [vendor/magento/framework/Interception/Interceptor.PHP:58]
#23 Magento\Backend\App\Router\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.PHP:138]
#24 Magento\Backend\App\Router\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.PHP:153]
#25 Magento\Backend\App\Router\Interceptor->___callPlugins() called at [generated/code/Magento/Backend/App/Router/Interceptor.PHP:26]
#26 Magento\Backend\App\Router\Interceptor->match() called at [vendor/magento/framework/App/FrontController.PHP:115]
#27 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.PHP:58]
#28 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.PHP:138]
#29 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.PHP:153]
#30 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.PHP:26]
#31 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.PHP:116]
#32 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.PHP:263]
#33 Magento\Framework\App\Bootstrap->run() called at [pub/index.PHP:40]
</pre>

我将其范围缩小到magento/module-csp,将Magento\Csp\Model\BlockCache设置为configured_block_cache,因此将其设置在generated/Metadata/frontend.PHP(及其他)中

摘录自vendor/magento/module-csp/etc/di.xml:93

...
<type name="Magento\Csp\Model\BlockCache">
    <arguments>
        <argument name="cache" xsi:type="object">configured_block_cache</argument>
    </arguments>
</type>
...

摘录自generated/Metadata/frontend.PHP

...
'Magento\\Csp\\Model\\BlockCache' =>
array (
  'cache' =>
  array (
    '_i_' => 'configured_block_cache',),'dynamicCollector' =>
  array (
    '_i_' => 'Magento\\Csp\\Model\\Collector\\DynamicCollector','serializer' =>
  array (
    '_i_' => 'Magento\\Framework\\Serialize\\Serializer\\Json',...

我不知道为什么会出现此错误

我已经在数据库搜索了多种形式的单词缓存和/或csp

还有其他遇到类似情况并且知道解决方案的人吗?

解决方法

从Magento 2.3.4升级到2.4时遇到了相同的问题。查看现有的Magento 2.4环境后,我注意到“ app / etc / di.xml”中缺少以下几行:

<virtualType name="configured_block_cache" type="Magento\Framework\App\Cache">
    <arguments>
        <argument name="cacheIdentifier" xsi:type="string">block_html</argument>
    </arguments>
</virtualType>
<type name="Magento\Framework\View\Element\Context">
    <arguments>
        <argument name="cache" xsi:type="object">configured_block_cache</argument>
    </arguments>
</type>
<type name="Magento\Framework\DB\Adapter\SqlVersionProvider">
    <arguments>
        <argument name="supportedVersionPatterns" xsi:type="array">
            <item name="MySQL-8" xsi:type="string">^8\.0\.</item>
            <item name="MySQL-5.7" xsi:type="string">^5\.7\.</item>
            <item name="MariaDB-(10.2-10.4)" xsi:type="string">^10\.[2-4]\.</item>
        </argument>
    </arguments>
</type>
<type name="Magento\Framework\View\TemplateEngine\Php">
    <arguments>
        <argument name="blockVariables" xsi:type="array">
            <item name="secureRenderer" xsi:type="object">Magento\Framework\View\Helper\SecureHtmlRenderer\Proxy</item>
            <item name="escaper" xsi:type="object">Magento\Framework\Escaper</item>
        </argument>
    </arguments>
</type>

添加这些行并清除缓存后,错误将得到解决。我不确定为什么在升级到2.4时不添加这些行,而在安装全新安装时是为什么。