不能使用Doctrine 2.0查询缓存结果

时间:2013-08-05 12:16:29

标签: doctrine

我正在尝试使用Doctrine 2.0的结果缓存来提高应用程序的性能。

查询中的setResultCacheImpl()和useResultCache(true)与APC一起用作缓存。

调试我可以看到\Doctrine\ORM\AbstractQuery->execute被调用但从未找到缓存数据。 原因是从缓存中读取数据时永远不会设置$cached[$id]。查看下面的Doctrine代码,我也看不出应该如何设置$cached[$id]

    // Check result cache
    if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) {
        list($id, $hash) = $this->getResultCacheId();

        $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
        if ($cached === false || !isset($cached[$id])) {
            // Cache miss.
            $stmt = $this->_doExecute();

            $result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll(
                    $stmt, $this->_resultSetMapping, $this->_hints
                    );
            $cacheDriver->save($id, $result, $this->_resultCacheTTL);

            return $result;
        } else {
            // Cache hit.
            return $cached[$id];
        }
    }

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

要解决此问题,您需要从Doctrine 2.0.x存储库中应用修补程序:https://github.com/doctrine/doctrine2/commit/4271706cabdf6f7a99ffbe6aad0efcec1584f562

相关问题