From 3515df913f2e4636d351fd560571dd0a49b835fb Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 23 Jan 2011 20:53:20 +0100 Subject: [PATCH] DDC-892 - Implement separate chaining approach for result caches to prevent hash colissions. --- lib/Doctrine/ORM/AbstractQuery.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3de3ede6b..5c7f0747a 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -506,10 +506,10 @@ abstract class AbstractQuery // Check result cache if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) { - $id = $this->_getResultCacheId(); + list($id, $hash) = $this->getResultCacheId(); $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id); - if ($cached === false) { + if ($cached === false || !isset($cached[$id])) { // Cache miss. $stmt = $this->_doExecute(); @@ -522,7 +522,7 @@ abstract class AbstractQuery return $result; } else { // Cache hit. - return $cached; + return $cached[$id]; } } @@ -556,12 +556,12 @@ abstract class AbstractQuery * Will return the configured id if it exists otherwise a hash will be * automatically generated for you. * - * @return string $id + * @return array ($id, $hash) */ - protected function _getResultCacheId() + protected function getResultCacheId() { if ($this->_resultCacheId) { - return $this->_resultCacheId; + return array($this->_resultCacheId, $this->_resultCacheId); } else { $params = $this->_params; foreach ($params AS $key => $value) { @@ -573,13 +573,16 @@ abstract class AbstractQuery $idValues = $class->getIdentifierValues($value); } $params[$key] = $idValues; + } else { + $params[$key] = $value; } } $sql = $this->getSql(); ksort($this->_hints); - return md5(implode(";", (array)$sql) . var_export($params, true) . - var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode); + $key = implode(";", (array)$sql) . var_export($params, true) . + var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode; + return array($key, md5($key)); } }