summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
diff options
context:
space:
mode:
authorwei <>2006-04-14 11:23:56 +0000
committerwei <>2006-04-14 11:23:56 +0000
commitf6a5e7589396854e10e023c25237b47e512ff047 (patch)
tree2b313bb8b66869235ee06b9cae2af2f7645cf5c9 /framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
parent3d3f8d3832921f99daf8ce1953304763c2e76c62 (diff)
Adding SQLMap unit tests. Allow sqlmap to use Prado's caching module to cache records.
Diffstat (limited to 'framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php')
-rw-r--r--framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php73
1 files changed, 70 insertions, 3 deletions
diff --git a/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php b/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
index 8571d46d..a62a7432 100644
--- a/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
+++ b/framework/DataAccess/SQLMap/DataMapper/TSqlMapCache.php
@@ -1,6 +1,6 @@
<?php
/**
- * TSqlMapCache class file contains FIFO and LRU cache implementations.
+ * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
@@ -20,7 +20,7 @@ interface ISqLMapCache
public function set($key, $value);
- public function configure($properties);
+ public function configure($model, $properties);
}
/**
@@ -54,7 +54,7 @@ abstract class TSqlMapCache implements ISqlMapCache
* Configures the Cache Size.
* @param array list of properties
*/
- public function configure($properties)
+ public function configure($model, $properties)
{
if(isset($properties['size']))
$this->_cacheSize = intval($properties['size']);
@@ -161,5 +161,72 @@ class TSqlMapLruCache extends TSqlMapCache
}
}
+class TSqlMapApplicationCache implements ISqlMapCache
+{
+ private $_cache;
+ private $_expiry=0;
+ private $_property=array();
+ private $_cacheModelID;
+
+ public function __sleep()
+ {
+ $this->_cache = null;
+ return array_keys(get_object_vars($this));
+ }
+
+ public function remove($key)
+ {
+ $this->getCache()->delete($key);
+ }
+
+ public function flush()
+ {
+ $this->getCache()->flush();
+ }
+
+ public function get($key)
+ {
+ $result = $this->getCache()->get($key);
+ return $result === false ? null : $result;
+ }
+
+ public function set($key, $value)
+ {
+ $this->getCache()->set($key, $value, $this->_expiry);
+ }
+
+ public function configure($model, $properties)
+ {
+ $this->_property = $properties;
+ $this->_cacheModelID = $model->getID();
+ }
+
+ protected function getCache()
+ {
+ if(is_null($this->_cache))
+ $this->initialize();
+ return $this->_cache;
+ }
+
+ protected function initialize()
+ {
+ if(isset($this->_property['expiry']))
+ $this->_expiry = intval($this->_property['expiry']);
+
+ if(isset($this->_property['cacheModule']))
+ {
+ $id = $this->_property['cacheModule'];
+ $this->_cache = Prado::getApplication()->getModule($id);
+ }
+ else
+ {
+ $this->_cache = Prado::getApplication()->getCache();
+ }
+
+ if(!($this->_cache instanceof ICache))
+ throw new TSqlMapConfigurationException(
+ 'sqlmap_invalid_prado_cache', $this->_cacheModelID);
+ }
+}
?> \ No newline at end of file