- ndex: lib/Doctrine/ORM/AbstractQuery.php
- ===================================================================
- --- lib/Doctrine/ORM/AbstractQuery.php (revision 7127)
- +++ lib/Doctrine/ORM/AbstractQuery.php (working copy)
- -488,7 +488,7 @@
- // Check result cache
- if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) {
- - $id = $this->getResultCacheId($params);
- + $id = $this->_getResultCacheId($params);
- $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
- if ($cached === false) {
- -541,12 +541,14 @@
- * @param array $params
- * @return string $id
- */
- - public function getResultCacheId(array $params)
- + protected function _getResultCacheId(array $params)
- {
- if ($this->_resultCacheId) {
- return $this->_resultCacheId;
- } else {
- - return md5($this->getDql() . var_export($params, true));
- + $sql = $this->getSql();
- + ksort($this->_hints);
- + return md5(implode(";", (array)$sql) . var_export($params, true) . var_export($this->_hints, true));
- }
- }
- Index: lib/Doctrine/ORM/Query.php
- ===================================================================
- --- lib/Doctrine/ORM/Query.php (revision 7127)
- +++ lib/Doctrine/ORM/Query.php (working copy)
- -173,11 +173,7 @@
- {
- // Check query cache
- if ($queryCache = $this->getQueryCacheDriver()) {
- - // Calculate hash for dql query.
- - // TODO: Probably need to include query hints in hash calculation, because query hints
- - // can have influence on the SQL.
- - // TODO: Include _maxResults and _firstResult in hash calculation
- - $hash = md5($this->getDql() . 'DOCTRINE_QUERY_CACHE_SALT');
- + $hash = $this->_getQueryCacheId();
- $cached = ($this->_expireQueryCache) ? false : $queryCache->fetch($hash);
- if ($cached === false) {
- -438,4 +434,21 @@
- $this->setHint(self::HINT_INTERNAL_ITERATION, true);
- return parent::iterate($params, $hydrationMode);
- }
- +
- + /**
- + * Generate a cache id for the query cache - reusing the Result-Cache-Id generator.
- + *
- + * The query cache
- + *
- + * @return string
- + */
- + protected function _getQueryCacheId()
- + {
- + ksort($this->_hints);
- +
- + return md5(
- + $this->getDql() . var_export($this->_hints, true) .
- + 'firstResult='.$this->_firstResult.'&maxResult='.$this->_maxResults.'DOCTRINE_QUERY_CACHE_SALT'
- + );
- + }
- }
- \ No newline at end of file