From 5a96217d4d1c4a554f86dc50b6faa4838c678042 Mon Sep 17 00:00:00 2001 From: beberlei Date: Sat, 13 Feb 2010 21:42:09 +0000 Subject: [PATCH] [2.0] DDC-328 - Query and Result Cache Keys now depend on the hydrationMode also --- lib/Doctrine/ORM/AbstractQuery.php | 3 ++- lib/Doctrine/ORM/Query.php | 3 ++- .../Tests/ORM/Functional/QueryCacheTest.php | 13 +++++++++++++ .../Tests/ORM/Functional/ResultCacheTest.php | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index fd1766923..9d0a2da27 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -548,7 +548,8 @@ abstract class AbstractQuery } else { $sql = $this->getSql(); ksort($this->_hints); - return md5(implode(";", (array)$sql) . var_export($params, true) . var_export($this->_hints, true)); + return md5(implode(";", (array)$sql) . var_export($params, true) . + var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode); } } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 5a4bc9d3b..80f13bc33 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -448,7 +448,8 @@ final class Query extends AbstractQuery return md5( $this->getDql() . var_export($this->_hints, true) . - 'firstResult='.$this->_firstResult.'&maxResult='.$this->_maxResults.'DOCTRINE_QUERY_CACHE_SALT' + '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . + '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 504db0abe..1d95d0ca1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -67,6 +67,19 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($cacheCount + 1, count($cache->getIds())); } + /** + * @param $query + * @depends testQueryCache_DependsOnHints + */ + public function testQueryCache_DependsOnHydrationMode($query) + { + $cache = $query->getQueryCacheDriver(); + $cacheCount = count($cache->getIds()); + + $query->getArrayResult(); + $this->assertEquals($cacheCount + 1, count($cache->getIds())); + } + public function testQueryCache_NoHitSaveParserResult() { $this->_em->getConfiguration()->setQueryCacheImpl(null); diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index cfd1e39f5..05bd8333d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -131,4 +131,19 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($cacheCount + 1, count($cache->getIds())); } + + /** + * @param $query + * @depends testNativeQueryResultCaching + */ + public function testResultCacheDependsOnHydrationMode($query) + { + $cache = $query->getResultCacheDriver(); + $cacheCount = count($cache->getIds()); + + $this->assertNotEquals(\Doctrine\ORM\Query::HYDRATE_ARRAY, $query->getHydrationMode()); + $query->getArrayResult(); + + $this->assertEquals($cacheCount + 1, count($cache->getIds())); + } } \ No newline at end of file