Home > Enterprise >  How to make Doctrine result cache work with Redis on Symfony 3.4
How to make Doctrine result cache work with Redis on Symfony 3.4

Time:08-27

Currently I have this on framework.cache:

app: cache.adapter.redis
default_redis_provider: redis://localhost

doctrine.orm:

metadata_cache_driver: redis
result_cache_driver: redis
query_cache_driver: redis

Sure, it doesn't work, but I have no idea what to even try now. Doing type: pool, pool: cache.app works perfect on Symfony 5/6, but it doesn't do anything on Symfony 3.4, anyone have any ideas?

CodePudding user response:

This works for me and maybe will be helpful for you too:

config/packages/cache.yaml

framework:
    cache:
        prefix_seed: '%env(resolve:APP_NAME)%'
        app: cache.adapter.redis
        default_redis_provider: '%env(resolve:REDIS_DSN)%'
        pools:
            doctrine.result_cache_pool:
                adapter: redis_adapter
                provider: redis_provider
            doctrine.system_cache_pool:
                adapter: cache.adapter.apcu

config/packages/prod/doctrine.yaml

doctrine:
    dbal:
    # ...
    orm:
        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

CodePudding user response:

Sooo 5 mins after posting I have the answer, everything was in prod/doctrine.yaml...

doctrine.orm:

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

framework.cache:

app: cache.adapter.redis
system: cache.adapter.redis
default_redis_provider: redis://localhost

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'
  • Related