1
0
mirror of synced 2024-12-13 14:56:01 +03:00

DDC-1026 - Fix Result Cache Seperate chaining implementation that was wrong since DDC-892 was applied.

This commit is contained in:
Benjamin Eberlei 2011-02-26 00:38:06 +01:00
parent 9125413786
commit 1eb7f92956
2 changed files with 35 additions and 6 deletions

View File

@ -506,10 +506,10 @@ abstract class AbstractQuery
// Check result cache
if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) {
list($id, $hash) = $this->getResultCacheId();
$cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
list($key, $hash) = $this->getResultCacheId();
$cached = $this->_expireResultCache ? false : $cacheDriver->fetch($hash);
if ($cached === false || !isset($cached[$id])) {
if ($cached === false || !isset($cached[$key])) {
// Cache miss.
$stmt = $this->_doExecute();
@ -517,12 +517,12 @@ abstract class AbstractQuery
$stmt, $this->_resultSetMapping, $this->_hints
);
$cacheDriver->save($id, $result, $this->_resultCacheTTL);
$cacheDriver->save($hash, array($key => $result), $this->_resultCacheTTL);
return $result;
} else {
// Cache hit.
return $cached[$id];
return $cached[$key];
}
}
@ -556,7 +556,7 @@ abstract class AbstractQuery
* Will return the configured id if it exists otherwise a hash will be
* automatically generated for you.
*
* @return array ($id, $hash)
* @return array ($key, $hash)
*/
protected function getResultCacheId()
{

View File

@ -86,6 +86,35 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache());
}
/**
* @group DDC-1026
*/
public function testUseResultCacheParams()
{
$cache = new \Doctrine\Common\Cache\ArrayCache();
$this->_em->getConfiguration()->setResultCacheImpl($cache);
$sqlCount = count($this->_sqlLoggerStack->queries);
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1');
$query->setParameter(1, 1);
$query->useResultCache(true);
$query->getResult();
$query->setParameter(1, 2);
$query->getResult();
$this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "Two non-cached queries.");
$query->setParameter(1, 1);
$query->useResultCache(true);
$query->getResult();
$query->setParameter(1, 2);
$query->getResult();
$this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "The next two sql should have been cached, but were not.");
}
public function testNativeQueryResultCaching()
{
$rsm = new \Doctrine\ORM\Query\ResultSetMapping();