Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用symfony2在doctrine2中缓存和使db请求无效的最佳实践是什么?_Php_Symfony_Caching_Doctrine Orm - Fatal编程技术网

Php 使用symfony2在doctrine2中缓存和使db请求无效的最佳实践是什么?

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-&

我有一个来自存储库的奇怪代码,灵感来自 “奥克拉米乌斯(一位教士)也在这里说”

我不想使用$query->useResultCache(true,60,'other_cach_key');因为它解析请求“从AppBundle中选择c:Culture c”,这会降低性能。所以我决定使用QueryCacheDriver

但要得到它,我必须创建空查询! $query=$this->getEntityManager()->createQuery()

以及控制器中的失效

    $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');