Permalink
Browse files

[DDC-1766] Explain details of Hydration cache, introduce AbstractQuer…

…y#setResultCacheProfile method
  • Loading branch information...
1 parent c32a77e commit d31c7f5e2b2a0bedcebbf44330dcdca9b9c794f0 @beberlei beberlei committed Apr 4, 2012
Showing with 25 additions and 0 deletions.
  1. +25 −0 lib/Doctrine/ORM/AbstractQuery.php
@@ -311,6 +311,12 @@ public function setResultSetMapping(Query\ResultSetMapping $rsm)
* 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";
@@ -339,6 +345,25 @@ public function getHydrationCacheProfile()
}
/**
+ * 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.
*
* @param \Doctrine\Common\Cache\Cache $driver Cache driver

0 comments on commit d31c7f5

Please sign in to comment.