Caching 如何使Symfony2 DIC调用条令\ORM\Configuration#setHydrationCacheImpl()
对于较新版本的Doctrine2,我知道有Caching 如何使Symfony2 DIC调用条令\ORM\Configuration#setHydrationCacheImpl(),caching,symfony,doctrine-orm,Caching,Symfony,Doctrine Orm,对于较新版本的Doctrine2,我知道有Doctrine\ORM\Configuration#setHydrationCacheImpl() 传递,如MemcacheCache等 但如何在容器中完成呢 我正在使用两个实体管理器:名为“default”和“other” 我第一次尝试像这样在config.yml中定义缓存 doctrine: orm: default_entity_manager: default ... entity_man
Doctrine\ORM\Configuration#setHydrationCacheImpl()
传递,如MemcacheCache等
但如何在容器中完成呢
我正在使用两个实体管理器:名为“default”和“other”
我第一次尝试像这样在config.yml中定义缓存
doctrine:
orm:
default_entity_manager: default
...
entity_managers:
default:
...
metadata_cache_driver:
type: service
id: memcache_driver
...
hydration_cache_driver:
type: service
id: memcache_driver
...
other:
...
注意:memcache\u驱动程序
由我定义,instanceofDoctrine\Common\Cache\MemcacheCache
然后我在“doctrine.orm.entity\u managers.default”下得到了无法识别的选项“缓存驱动程序”
我还尝试直接调整AppKernel#buildContainer中的容器,
但没有定义为服务的\doctor\ORM\Configuration实例,
因此,我无法检索配置实例
欢迎提出任何建议
编辑:
我确信,从第2.2.2条开始,缓存水合对象的功能已经重新实现
对于其他简单的服务,我可以通过覆盖整个定义轻松添加要调用的方法,如
service1:
...
calls:
[method calls]
但是对于实体管理器,我不知道如何向它们添加方法调用
换句话说,我的问题是,如何在不使用语义配置的情况下在较低级别配置orm?没有“缓存驱动程序”这样的选项,您应该使用“结果缓存驱动程序”来实现这一点
从Doctrine 2.1开始,Doctrine可以缓存查询结果,但在水合作用后不会缓存对象
查看有关条令配置的文档:
没有“缓存驱动程序”这样的选项,您应该使用“结果缓存驱动程序”来实现这一点
从Doctrine 2.1开始,Doctrine可以缓存查询结果,但在水合作用后不会缓存对象
查看有关条令配置的文档:
在我的例子中,由于水化缓存很少使用, 所以这次我决定在执行每个查询之前调用Query#setHydrationCacheProfile
...
$query = $queryBuilder->getQuery();
$cache = $this->container->get('...'); //instanceof MemcacheCache
$query->setHydrationCacheProfile(new CacheProfile(null, null $cache));
$query->execute();
...
在我的例子中,由于水化缓存很少使用, 所以这次我决定在执行每个查询之前调用Query#setHydrationCacheProfile
...
$query = $queryBuilder->getQuery();
$cache = $this->container->get('...'); //instanceof MemcacheCache
$query->setHydrationCacheProfile(new CacheProfile(null, null $cache));
$query->execute();
...
谢谢你的回复!是的,它被禁用一次,但从2.2.2开始重新实现为缓存。请看我的编辑。谢谢你的回复!是的,它被禁用一次,但从2.2.2开始重新实现为缓存。请参阅我的编辑。