From d31c7f5e2b2a0bedcebbf44330dcdca9b9c794f0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 4 Apr 2012 23:55:14 +0200 Subject: [PATCH] [DDC-1766] Explain details of Hydration cache, introduce AbstractQuery#setResultCacheProfile method --- lib/Doctrine/ORM/AbstractQuery.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3fba6c4cd..f2a20fa0f 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -311,6 +311,12 @@ abstract class AbstractQuery * If no result cache driver is set in the QueryCacheProfile, the default * result cache driver is used from the configuration. * + * Important: Hydration caching does NOT register entities in the + * UnitOfWork when retrieved from the cache. Never use result cached + * entities for requests that also flush the EntityManager. If you want + * some form of caching with UnitOfWork registration you should use + * {@see AbstractQuery::setResultCacheProfile()}. + * * @example * $lifetime = 100; * $resultKey = "abc"; @@ -338,6 +344,25 @@ abstract class AbstractQuery return $this->_hydrationCacheProfile; } + /** + * Set a cache profile for the result cache. + * + * If no result cache driver is set in the QueryCacheProfile, the default + * result cache driver is used from the configuration. + * + * @param \Doctrine\DBAL\Cache\QueryCacheProfile $profile + * @return \Doctrine\ORM\AbstractQuery + */ + public function setResultCacheProfile(QueryCacheProfile $profile = null) + { + if ( ! $profile->getResultCacheDriver()) { + $profile = $profile->setResultCacheDriver($this->_em->getConfiguration()->getResultCacheImpl()); + } + + $this->_queryCacheProfile = $profile; + return $this; + } + /** * Defines a cache driver to be used for caching result sets and implictly enables caching. *