首页 > 解决方案 > 升级到 Magento 2.4 后,我得到“类已配置_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\BlockCacheasconfigured_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

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

标签: phpmagentomagento2

解决方案


从 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 时没有添加这些行,而是在安装全新安装时添加。


推荐阅读