Doctrine query_cache auto expire

Viewed 1024

I'm using symfony 3.4 + doctrine + redis by using the composer bundle sncRedisBundle

In my config.yml I enabled doctrine query cache:

orm:
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            auto_mapping: false
            metadata_cache_driver: redis
            query_cache_driver: redis
            result_cache_driver: redis # !!!

snc_redis:
clients:

    doctrine:
        type: predis
        alias: doctrine_redis
        dsn: "%redis_dsn_doctrine%"
        logging: false
        options:
            connection_persistent: true

doctrine:
    query_cache: #!!!!!!!!
      #it caches the translation from Doctrine's DQL into SQL.
        client: doctrine_redis
        namespace: shop_doctrine_query  
        entity_manager: [default, legacy]

The keys set by doctrine for it's result_cache never expire: enter image description here

How can I call automatically \Doctrine\ORM\Query::setQueryCacheLifetime or make that cache expire. (Note I don't have access to set redis eviction policies on this server).

1 Answers

I think that Doctrine query cache lifetime aren't configured in the doctrine package nor in the redis package, but in the framework package, where you set your pool of cache.

You should have a look on this issue where a user is asking how to configure RedisCluster with Doctrine Cache. B-Galati answers with a configuration example where it defines lifetime for doctrine result cache.

Could you try something like:

framework:
    cache:
        pools:
            cache.doctrine.orm.default.query: ## I'm not sure of this name
                adapter: cache.app
                default_lifetime: 25200 # 1 week

Or

framework:
    cache:
        pools:
            doctrine.query_cache_pool:
                adapter: cache.app
                default_lifetime: 25200 # 1 week

The symfony console cache:pool:list command could help you to identify your pools and the symfony console cache:pool:prune could help you to see if out of date queries are well deleted.

Related