How to configure apcu for doctrine in Symfony5
Asked Answered
D

1

7

In Symfony4 I was using the following configuration for doctrine apcu caching:

doctrine:
    orm:
        auto_mapping: true
        auto_generate_proxy_classes: false
        metadata_cache_driver: apcu
        query_cache_driver: apcu
        result_cache_driver: apcu

After upgrading to Symfony5 I am getting an error:

Unknown cache of type "apc" configured for cache "metadata_cache" in entity manager "default".

When changing the it to the following configuration it works:

doctrine:
    orm:
        auto_mapping: true
        auto_generate_proxy_classes: false
        metadata_cache_driver:
            type: pool
            pool: doctrine.system_cache_pool
        query_cache_driver:
            type: pool
            pool: doctrine.system_cache_pool
        result_cache_driver:
            type: pool
            pool: doctrine.result_cache_pool

But what kind of cache am I using now? And how can I switch it to apcu?

Derange answered 26/3, 2020 at 7:10 Comment(0)
D
16

I had the same problem in Symfony 4.4.5

You should first install the Symfony Cache Component. Then, you should configure cache pools, services and doctrine cache as follows:

doctrine:
    orm:
        auto_generate_proxy_classes: false
        metadata_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        query_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        result_cache_driver:
            type: service
            id: doctrine.result_cache_provider

services:
    doctrine.result_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.system_cache_pool'

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.adapter.apcu
            doctrine.system_cache_pool:
                adapter: cache.adapter.apcu

The above configration is taken from here.

Debbydebee answered 26/3, 2020 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.