在花了几天时间弄清楚为什么我的doctrine的二级缓存配置不起作用后,我希望有人能支持我。目前,没有二级缓存调用导致命中。
我的项目当前是使用以下包设置的(+其他一些可能与此设置无关的包):
"symfony/symfony": "2.6.*",
"doctrine/orm": "2.*",
"doctrine/dbal": "2.*",
"doctrine/doctrine-bundle": "~1.2"
...
"snc/redis-bundle": "1.*"
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
元数据和查询缓存似乎工作正常,因为在Redis中创建了键,SNC Redis Bundle也正确地记录了我的缓存命中。但是"2l缓存“只记录未命中和But,而不是命中:
在调试期间,我发现在缓存中,来自Doctrine/ORM/Query的请求试图访问ArrayCache,而不是配置的缓存驱动程序。
如果有人有一个二级缓存的工作示例配置,它可能已经有所帮助,因为它既不适用于Redis for me,也不适用于APCu或memcached。
我希望有人有一个想法,或者可以分享他的工作配置。
提前致谢&致以最良好的敬意
发布于 2015-12-27 05:49:56
好了,大约一个月后,我终于得到了答案!
请注意,Doctrine原生支持许多缓存驱动程序,包括redis,但在我的情况下,可能在OP的情况下也是如此,我需要让它与SncRedisBundle一起工作,以便利用Redis主从复制和/或集群。
我在Github here 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
....
然后在你的config.yml中
....
orm:
entity_managers:
default:
second_level_cache:
region_cache_driver:
type: service
id: snc_second_level_cache
enabled: true
....
就这样,尽情享受吧!
更新- 2016年1月19日
到今天为止,Doctrine master分支现在是兼容的,并且集成了对SncRedisBundle二级缓存的支持
发布于 2015-10-08 21:33:46
您还需要为二级缓存启用正确的cache_driver
:
second_level_cache:
region_cache_driver:
type: service
id: doctrine_cache.providers.second_level
enabled: true
regions:
region_name:
cache_driver:
type: service
id: doctrine_cache.providers.second_level
这是一个与DoctrineCacheBundle
结合使用的示例。
https://stackoverflow.com/questions/32289787
复制相似问题