summaryrefslogtreecommitdiff
path: root/lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-02-24 23:18:07 +0100
committeremkael <emkael@tlen.pl>2016-02-24 23:18:07 +0100
commit6f7fdef0f500cd4bb540affd3bc1482243f337c1 (patch)
tree4853eecd0769a903e6130c1896e1d070848150dd /lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
parent61f2ea48a4e11cb5fb941b3783e19c9e9ef38a45 (diff)
* Prado 3.3.0
Diffstat (limited to 'lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php')
-rw-r--r--lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php b/lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
new file mode 100644
index 0000000..ec05978
--- /dev/null
+++ b/lib/prado/framework/Data/SqlMap/DataMapper/TFastSqlMapApplicationCache.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * TFastSqlMapApplicationCache class file contains Fast SqlMap cache implementation.
+ *
+ * @author Berczi Gabor <gabor.berczi@devworx.hu>
+ * @link https://github.com/pradosoft/prado
+ * @copyright Copyright &copy; 2005-2015 The PRADO Group
+ * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
+ * @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>
+ * @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');
+ }
+}