From 41ae873048d53ca767acf1623e50d5571a93f7c6 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 9 Jan 2012 08:26:07 +0100 Subject: [PATCH] DDC-1588 - Improve ResultCache API. The default cache impl is passed to new query cache profiles automatically now. --- lib/Doctrine/ORM/AbstractQuery.php | 4 ++-- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3fe27f93b..866febcca 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -316,7 +316,7 @@ abstract class AbstractQuery $this->_queryCacheProfile = $this->_queryCacheProfile ? $this->_queryCacheProfile->setLifetime($lifetime) - : new QueryCacheProfile($lifetime); + : new QueryCacheProfile($lifetime, null, $this->_em->getConfiguration()->getResultCacheImpl()); return $this; } @@ -615,7 +615,7 @@ abstract class AbstractQuery { $this->_queryCacheProfile = $this->_queryCacheProfile ? $this->_queryCacheProfile->setCacheKey($id) - : new QueryCacheProfile(0, $id); + : new QueryCacheProfile(0, $id, $this->_em->getConfiguration()->getResultCacheImpl()); return $this; } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index b1d2bee23..4e142e149 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\ORM\Query; -require_once __DIR__ . '/../../TestInit.php'; +use Doctrine\Common\Cache\ArrayCache; class QueryTest extends \Doctrine\Tests\OrmTestCase { @@ -90,4 +90,15 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('baz', $q->getHint('bar')); $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $q->getHints()); } -} \ No newline at end of file + + /** + * @group DDC-1588 + */ + public function testQueryDefaultResultCache() + { + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + $q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a"); + $q->useResultCache(true); + $this->assertSame($this->_em->getConfiguration()->getResultCacheImpl(), $q->getQueryCacheProfile()->getResultCacheDriver()); + } +}