summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php')
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index d7984dc4..d85148eb 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -38,8 +38,9 @@ class TSqlMapCacheModel extends TComponent
private $_hits = 0;
private $_requests = 0;
private $_id;
- private $_implementation='basic';
+ private $_implementation=TSqlMapCacheTypes::Basic;
private $_properties = array();
+ private $_flushInterval = 0;
/**
* @return string unique cache model identifier.
@@ -74,12 +75,28 @@ class TSqlMapCacheModel extends TComponent
}
/**
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ */
+ public function setFlushInterval($value)
+ {
+ $this->_flushInterval=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer cache duration.
+ */
+ public function getFlushInterval()
+ {
+ return $this->_flushInterval;
+ }
+
+ /**
* Initialize the cache implementation, sets the actual cache contain if supplied.
* @param ISqLMapCache cache implementation instance.
*/
public function initialize($cache=null)
{
- if(is_null($cache))
+ if($cache===null)
$this->_cache= Prado::createComponent($this->getImplementationClass());
else
$this->_cache=$cache;
@@ -127,7 +144,7 @@ class TSqlMapCacheModel extends TComponent
//if flush ?
$value = $this->_cache->get($key);
$this->_requests++;
- if(!is_null($value))
+ if($value!==null)
$this->_hits++;
return $value;
}
@@ -141,8 +158,8 @@ class TSqlMapCacheModel extends TComponent
if($key instanceof TSqlMapCacheKey)
$key = $key->getHash();
- if(!is_null($value))
- $this->_cache->set($key, $value);
+ if($value!==null)
+ $this->_cache->set($key, $value, $this->_flushInterval);
}
/**