如何在 Symfony、Doctrine ORM 和 DoctrineCacheBundle 中使用 ApcuCache

How to use ApcuCache with Symfony, Doctrine ORM and DoctrineCacheBundle

在我遇到这个问题之前,项目是 运行 on PHP5.6 on SF2.6.

我现在使用 PHP7.1.20 和 SF2.8。我在 docker 容器中安装了 apcu 和 apcu_bc 并启用了 apcu php 模块。

现在错误是:

UndefinedFunctionException in ApcCache.php line 35:
Attempted to call function "apc_exists" from the global namespace.

当我将加载的 ApcCache-Class 中的实际函数调用从 apc_ 更改为 apcu_ 时,一切正常。

里面Doctrine\Common\Cache都是类,ApcCache-和ApcuCache-Class。我不知道如何告诉学说 ORM/CacheBundle 使用 ApcuCache-Class 而不是 Apc 一个。

学说配置:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                persistent: true
                wrapper_class: 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection'
                driver_class: 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Driver\PDOMySql\Driver'
                server_version: '5.7'
                options:
                    x_reconnect_attempts: 3
            jato:
                driver:   "%database_jato_driver%"
                host:     "%database_jato_host%"
                port:     "%database_jato_port%"
                dbname:   "%database_jato_name%"
                user:     "%database_jato_user%"
                password: "%database_jato_password%"
                charset:  UTF8
                persistent: true
                server_version: '5.7'

            drupal:
                driver:   "%database_drupal_driver%"
                host:     "%database_drupal_host%"
                port:     "%database_drupal_port%"
                dbname:   "%database_drupal_name%"
                user:     "%database_drupal_user%"
                password: "%database_drupal_password%"
                charset:  UTF8
                persistent: true
                server_version: '5.7'

        types:
            json: Sonata\Doctrine\Types\JsonType

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    SonataMediaBundle: ~
                    ApplicationSonataMediaBundle: ~
                    XFrontendBundle: ~
                query_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache
                metadata_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache
                result_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache

            jato:
                connection: jato
                mappings:
                    XBackendBundle: ~
                query_cache_driver: array
                metadata_cache_driver: array
                result_cache_driver: array
            drupal:
                connection: drupal

DoctrineCacheBundle 配置:

doctrine_cache:
    providers:
        chain_cache:
            chain:
                providers: [array_cache, apc_cache]
        apc_cache:
            type: apc
        array_cache:
            type: array

在缓存服务容器 (app/cache/prod/appProdProjectContainer.php) 中,我可以找到以下信息:

'doctrine_cache.providers.apc_cache' => 'getDoctrineCache_Providers_ApcCacheService',

其次是

/*
     * Gets the public 'doctrine_cache.providers.apc_cache' shared service.
     *
     * @return \Doctrine\Common\Cache\ApcCache
     */
    protected function getDoctrineCache_Providers_ApcCacheService()
    {
        return $this->services['doctrine_cache.providers.apc_cache'] = new \Doctrine\Common\Cache\ApcCache();
    }

 'validator.mapping.cache.apc.class' => 'Symfony\Component\Validator\Mapping\Cache\ApcCache',

'doctrine_cache.apc.class' => 'Doctrine\Common\Cache\ApcCache',
'doctrine.orm.cache.apc.class' => 'Doctrine\Common\Cache\ApcCache',

我需要配置或更新哪些内容才能实现仅使用 ApcuCache-Class 而不是 Apc。

其他作曲家信息:

doctrine/cache                           v1.8.0
doctrine/annotations                     v1.6.0             
doctrine/cache                           v1.8.0             
doctrine/collections                     v1.5.0             
doctrine/common                          v2.9.0             
doctrine/dbal                            v2.4.5             
doctrine/doctrine-bundle                 1.6.13             
doctrine/doctrine-cache-bundle           dev-master 
doctrine/event-manager                   v1.0.0             
doctrine/inflector                       v1.3.0             
doctrine/instantiator                    1.1.0              
doctrine/lexer                           v1.0.1             
doctrine/orm                             v2.4.8             
doctrine/persistence                     v1.0.1             
doctrine/reflection                      v1.0.0  

symfony/assetic-bundle                   v2.8.2             
symfony/monolog-bundle                   v2.12.1           
symfony/polyfill-apcu                    v1.9.0             
symfony/polyfill-ctype                   v1.9.0             
symfony/polyfill-intl-icu                v1.9.0             
symfony/polyfill-mbstring                v1.9.0             
symfony/polyfill-php54                   v1.9.0             
symfony/polyfill-php55                   v1.9.0             
symfony/polyfill-php56                   v1.9.0             
symfony/polyfill-php70                   v1.9.0             
symfony/polyfill-util                    v1.9.0             
symfony/security-acl                     v3.0.1             
symfony/swiftmailer-bundle               v2.6.7             
symfony/symfony                          v2.8.45

sonata-project/admin-bundle              3.39.0             
sonata-project/block-bundle              3.12.1             
sonata-project/cache                     2.0.1              
sonata-project/core-bundle               3.11.2             
sonata-project/datagrid-bundle           2.3.1              
sonata-project/doctrine-extensions       1.0.2              
sonata-project/doctrine-orm-admin-bundle 3.4.2              
sonata-project/easy-extends-bundle       2.5.0              
sonata-project/exporter                  1.9.1              
sonata-project/formatter-bundle          3.5.0              
sonata-project/intl-bundle               2.5.0              
sonata-project/jquery-bundle             1.10.2             
sonata-project/markitup-bundle           2.1.0              
sonata-project/media-bundle              3.15.0 

容器调试信息:

Information for Service "doctrine_cache.providers.apc_cache"
============================================================

 ------------------ ------------------------------------
  Option             Value
 ------------------ ------------------------------------
  Service ID         doctrine_cache.providers.apc_cache
  Class              Doctrine\Common\Cache\ApcCache
  Tags               -
  Scope              container
  Public             yes
  Synthetic          no
  Lazy               no
  Synchronized       no
  Abstract           no
  Autowired          no
  Autowiring Types   -
 ------------------ ------------------------------------    

我想这是正确的服务,我必须配置它以在实际的 ApcCache-Class.

上使用 ApcuCache-Class

非常感谢大家的帮助。

………………

可以只覆盖实际服务...

@/src/App/Bundle/Resources/config/services.yml :

doctrine_cache.providers.apc_cache:
        class: Doctrine\Common\Cache\ApcuCache

好吧..第一次symfony/doctrine/...努力学习...

任何进一步的解释仍然非常感谢。

祝你好运。