symfonydoctrinesymfony-3.4

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


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?


Solution

  • 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
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        arguments:
            - '@doctrine.system_cache_pool'
    

    Bonus edit. How to provide custom namespace:

    Create a pool service services:doctrine.cache_pool:

    doctrine.cache_pool:
        parent: 'cache.app'
        tags:
            - { name: 'cache.pool', namespace: 'app' }
    

    Then use it in a definition for doctrine.system_cache_provider '@doctrine.system_cache_pool' => '@doctrine.cache_pool'.