Doctrine查询缓存自动过期

4

我正在使用Symfony 3.4 + Doctrine + Redis,通过使用Composer Bundle sncRedisBundle

在我的config.yml中,我启用了Doctrine查询缓存

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 设置的键永不过期:enter image description here

我该如何自动调用 \Doctrine\ORM\Query::setQueryCacheLifetime,或使缓存失效?(注意,我无法在此服务器上设置redis清除策略。)


你能提供 config/packages/*/cache.yaml 文件和 symfony console cache:pool:list 的返回结果吗? - Alexandre Tranchant
1个回答

1

我认为Doctrine查询缓存生命周期既没有在Doctrine包中配置,也没有在Redis包中配置,而是在框架包中配置,您可以在其中设置缓存池。

您应该查看此问题,其中一个用户正在询问如何配置RedisCluster与Doctrine Cache。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 命令可以帮助您查看是否已经成功删除了过时的查询。


这个能在Symfony 3.4上工作吗?它似乎被忽略了。 - max4ever

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接