gst*_*ert 6 caching second-level-cache redis symfony doctrine-orm
在花了几天时间弄清楚为什么我的二级缓存配置为学说不起作用之后,我希望有人能够支持.目前没有二级缓存调用导致命中.
我的项目目前使用以下软件包进行设置(+其他一些可能与此设置无关的软件包):
"symfony/symfony": "2.6.*",
"doctrine/orm": "2.*",
"doctrine/dbal": "2.*",
"doctrine/doctrine-bundle": "~1.2"
...
"snc/redis-bundle": "1.*"
Run Code Online (Sandbox Code Playgroud)
Doctrine缓存的设置方式如下:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
metadata_cache_driver: redis
query_cache_driver: redis
result_cache_driver: redis
second_level_cache:
enabled: true
log_enabled: true
Run Code Online (Sandbox Code Playgroud)
元数据和查询缓存似乎正常工作,因为在Redis中创建了密钥,而SNC Redis Bundle也正确记录了我的缓存命中.但是"2l Cache"只记录未命中和放置,而不是命中:
在我的调试过程中,我发现在Doctrine/ORM/Query的缓存请求中尝试访问ArrayCache而不是配置的缓存驱动程序.
如果某人有二级缓存的工作示例配置,它可能已经有所帮助,因为它既不适用于我的Redis,也不适用于APCu或memcached.
我希望有人有想法或者可以分享他的工作配置.
在此先感谢您的问候
好的,所以大约一个月后我终于得到了答案!
请注意,Doctrine本身支持许多缓存驱动程序,包括redis,但在我的情况下,也可能在OP的情况下,我需要使它与SncRedisBundle一起使用,以便利用Redis主从复制和/或群集.
我在Github上得到了有用的反馈,我的回答是https://github.com/snc/SncRedisBundle/issues/216
基本上,您必须创建一个服务,该服务基本上是services.yml中的几行代码
....
services:
snc_second_level_cache:
class: %snc_redis.doctrine_cache.class%
calls:
- ["setRedis", ["@snc_redis.cache"]]
- ["setNamespace", ["DoctrineSecondLevelCache"]] #Optional
....
Run Code Online (Sandbox Code Playgroud)
然后在你的config.yml中
....
orm:
entity_managers:
default:
second_level_cache:
region_cache_driver:
type: service
id: snc_second_level_cache
enabled: true
....
Run Code Online (Sandbox Code Playgroud)
就是这样,享受吧!
更新 - 2016年1月19日
截至今日,SncRedisBundle dev-master分支现已兼容,并附带对Doctrine二级缓存的集成支持