Php 使用symfony2在doctrine2中缓存和使db请求无效的最佳实践是什么?
我有一个来自存储库的奇怪代码,灵感来自 “奥克拉米乌斯(一位教士)也在这里说” 我不想使用$query->useResultCache(true,60,'other_cach_key');因为它解析请求“从AppBundle中选择c:Culture c”,这会降低性能。所以我决定使用QueryCacheDriver 但要得到它,我必须创建空查询! $query=$this->getEntityManager()->createQuery() 以及控制器中的失效Php 使用symfony2在doctrine2中缓存和使db请求无效的最佳实践是什么?,php,symfony,caching,doctrine-orm,Php,Symfony,Caching,Doctrine Orm,我有一个来自存储库的奇怪代码,灵感来自 “奥克拉米乌斯(一位教士)也在这里说” 我不想使用$query->useResultCache(true,60,'other_cach_key');因为它解析请求“从AppBundle中选择c:Culture c”,这会降低性能。所以我决定使用QueryCacheDriver 但要得到它,我必须创建空查询! $query=$this->getEntityManager()->createQuery() 以及控制器中的失效 $em = $this-&
$em = $this->getDoctrine()->getManager();
$em->persist($culture);
$em->flush();
// cache invalidation!
$this->getDoctrine()->getEntityManager()->createQuery()->
getQueryCacheDriver()->delete('cache_key');
我觉得这代码有味道。但我不知道如何修复它!谁能为最佳实践提供建议
通常,我希望存储数据并在某些事件中使其无效
$em = $this->getDoctrine()->getManager();
$em->persist($culture);
$em->flush();
// cache invalidation!
$this->getDoctrine()->getEntityManager()->createQuery()->
getQueryCacheDriver()->delete('cache_key');