summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctrlaltca <>2012-05-29 10:01:36 +0000
committerctrlaltca <>2012-05-29 10:01:36 +0000
commita569b4bf5838fb67c2c453aa2af89f8f220e2337 (patch)
treeee06f210edcf56d619282900939ef4044354710f
parent21aa1d7bbcc46d3f76d3d60dd84b5def6905f783 (diff)
committed patch for #407
-rw-r--r--.gitattributes1
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php17
-rw-r--r--framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php89
3 files changed, 105 insertions, 2 deletions
diff --git a/.gitattributes b/.gitattributes
index 91241ef3..44c7afe4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3039,6 +3039,7 @@ framework/Data/SqlMap/Configuration/TSimpleDynamicParser.php -text
framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php -text
framework/Data/SqlMap/Configuration/TSqlMapStatement.php -text
framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php -text
+framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php -text
framework/Data/SqlMap/DataMapper/TLazyLoadList.php -text
framework/Data/SqlMap/DataMapper/TPropertyAccess.php -text
framework/Data/SqlMap/DataMapper/TSqlMapCache.php -text
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index c70cc48a..e33e8104 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -42,6 +42,13 @@ class TSqlMapCacheModel extends TComponent
private $_properties = array();
private $_flushInterval = 0;
+ private static $_cacheTypes = array();
+
+ public static function registerCacheType($type, $className)
+ {
+ self::$_cacheTypes[$type] = $className;
+ }
+
/**
* @return string unique cache model identifier.
*/
@@ -71,7 +78,10 @@ class TSqlMapCacheModel extends TComponent
*/
public function setImplementation($value)
{
- $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes');
+ if (isset(self::$_cacheTypes[$value]))
+ $this->_implementation = $value;
+ else
+ $this->_implementation = TPropertyValue::ensureEnum($value,'TSqlMapCacheTypes');
}
/**
@@ -107,7 +117,10 @@ class TSqlMapCacheModel extends TComponent
*/
public function getImplementationClass()
{
- switch(TPropertyValue::ensureEnum($this->_implementation,'TSqlMapCacheTypes'))
+ $implementation = $this->_implementation;
+ if (isset(self::$_cacheTypes[$implementation])) return self::$_cacheTypes[$implementation];
+
+ switch(TPropertyValue::ensureEnum($implementation,'TSqlMapCacheTypes'))
{
case TSqlMapCacheTypes::FIFO: return 'TSqlMapFifoCache';
case TSqlMapCacheTypes::LRU : return 'TSqlMapLruCache';
diff --git a/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php b/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
new file mode 100644
index 00000000..157189c1
--- /dev/null
+++ b/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * TFastSqlMapApplicationCache class file contains Fast SqlMap cache implementation.
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2011 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * TFastSqlMapApplicationCache class file
+ *
+ * Fast SqlMap result cache class with minimal-concurrency get/set and atomic flush operations
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @version $Id: TFastSqlMapApplicationCache.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
+ * @package System.Data.SqlMap
+ * @since 3.2
+ */
+
+class TFastSqlMapApplicationCache implements ICache
+{
+ protected $_cacheModel=null;
+ protected $_cache=null;
+
+ public function __construct($cacheModel=null)
+ {
+ $this->_cacheModel = $cacheModel;
+ }
+
+ protected function getBaseKeyKeyName()
+ {
+ return 'SqlMapCacheBaseKey::'.$this->_cacheModel->getId();
+ }
+
+ protected function getBaseKey()
+ {
+ $cache = $this->getCache();
+ $keyname = $this->getBaseKeyKeyName();
+ $basekey = $cache->get($keyname);
+ if (!$basekey)
+ {
+ $basekey = DxUtil::generateRandomHash(8);
+ $cache->set($keyname,$basekey);
+ }
+ return $basekey;
+ }
+
+ protected function getCacheKey($key)
+ {
+ return $this->getBaseKey().'###'.$key;
+ }
+
+ public function delete($key)
+ {
+ $this->getCache()->delete($this->getCacheKey($key));
+ }
+
+ public function flush()
+ {
+ $this->getCache()->delete($this->getBaseKeyKeyName());
+ }
+
+ public function get($key)
+ {
+ $result = $this->getCache()->get($this->getCacheKey($key));
+ return $result === false ? null : $result;
+ }
+
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->getCache()->set($this->getCacheKey($key), $value, $expire,$dependency);
+ }
+
+ protected function getCache()
+ {
+ if (!$this->_cache)
+ $this->_cache = Prado::getApplication()->getCache();
+ return $this->_cache;
+ }
+
+ public function add($id,$value,$expire=0,$dependency=null)
+ {
+ throw new TSqlMapException('sqlmap_use_set_to_store_cache');
+ }
+}