学说 query_cache 自动过期。

问题描述 投票:1回答:1

我在使用symfony 3.4 + doctrine + redis,使用的是composer bundle。sncRedisBundle

在我的config.yml中,我启用了 教义查询缓存:

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]

doctrine为它的result_cache设置的keys永远不会过期。enter image description here

我怎么能自动调用 \Doctrine\ORM\Query::setQueryCacheLifetime 或使该缓存过期。(注意我没有权限在这个服务器上设置redis驱逐策略)。

symfony redis doctrine-orm
1个回答
3
投票

学说,

查询缓存驱动程序默认从Doctrine\ORM\Configuration实例传递给每个Doctrine\ORM\Query实例,并且默认启用。

所以你可以使用。

Query::setQueryCacheLifeTime($seconds = 3600) - Set lifetime of the query caching.

如下:

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

0
投票

我认为Doctrine查询缓存寿命不是在doctrine包中配置的,也不是在redis包中配置的,而是在framework包中设置缓存池的。

你应该看看 本期 其中有用户询问如何配置带有Doctrine Cache的RedisCluster。B-Galati用一个配置实例来回答,它定义了doctrine结果缓存的生命周期。

你是否可以尝试一下这样的做法。

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

或者...

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

symfony console cache:pool:list 命令可以帮助你识别你的池子和 symfony console cache:pool:prune 可以帮助你查看过期的查询是否被很好的删除。

© www.soinside.com 2019 - 2024. All rights reserved.