From 9703f18ca898e3b6b7a15358ec521115f20a9b5e Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 29 Jun 2007 12:45:26 +0000 Subject: [PATCH] --- lib/Doctrine.php | 1 + lib/Doctrine/Hydrate.php | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine.php b/lib/Doctrine.php index 3f7116357..c7ee312b8 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -191,6 +191,7 @@ final class Doctrine const ATTR_NS_GAP_DECREASE_EXP = 132; const ATTR_CACHE = 150; + const ATTR_CACHE_LIFESPAN = 151; const ATTR_LOAD_REFERENCES = 153; /** diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 7bf8f4138..dbc70f57d 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -133,8 +133,14 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable * @var array */ protected $_cache; + /** + * @var boolean $_expireCache a boolean value that indicates whether or not to force cache expiration + */ + protected $_expireCache = false; + + protected $_timeToLive; - protected $_tableAliases = array(); + protected $_tableAliases = array(); /** * @var array $_tableAliasSeeds A simple array keys representing table aliases and values * as table alias seeds. The seeds are used for generating short table @@ -199,15 +205,27 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable } $this->_cache = $driver; - return $this->setTimeToLive($timeToLive); + return $this->setCacheLifeSpan($timeToLive); } /** - * setTimeToLive + * expireCache + * + * @param boolean $expire whether or not to force cache expiration + * @return Doctrine_Hydrate this object + */ + public function expireCache($expire = true) + { + $this->_expireCache = true; + + return $this; + } + /** + * setCacheLifeSpan * * @param integer $timeToLive how long the cache entry is valid * @return Doctrine_Hydrate this object */ - public function setTimeToLive($timeToLive) + public function setCacheLifeSpan($timeToLive) { if ($timeToLive !== null) { $timeToLive = (int) $timeToLive; @@ -745,7 +763,8 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable // calculate hash for dql query $hash = md5($dql . var_export($params, true)); - $cached = $cacheDriver->fetch($hash); + $cached = ($this->_expireCache) ? null : $cacheDriver->fetch($hash); + if ($cached === null) { // cache miss