summaryrefslogtreecommitdiff
path: root/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 22:02:33 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 22:02:33 +0100
commit90b5141367db5fcac9ba72042278556612b5dc3f (patch)
tree369112fd85eab39d36f4726f4f763828e6c560a4 /framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php
parentf6c4b70070a8e4378a37f750d53920e44bcc5857 (diff)
One class per file: framework/Data
Diffstat (limited to 'framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php')
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php
new file mode 100644
index 00000000..3c036a97
--- /dev/null
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Data.SqlMap
+ */
+
+/**
+ * First-in-First-out cache implementation, removes
+ * object that was first added when the cache is full.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @package System.Data.SqlMap
+ * @since 3.1
+ */
+class TSqlMapFifoCache extends TSqlMapCache
+{
+ /**
+ * @return mixed Gets a cached object with the specified key.
+ */
+ public function get($key)
+ {
+ return $this->_cache->itemAt($key);
+ }
+
+ /**
+ * Stores a value identified by a key into cache.
+ * The expire and dependency parameters are ignored.
+ * @param string cache key
+ * @param mixed value to cache.
+ */
+ public function set($key, $value,$expire=0,$dependency=null)
+ {
+ $this->_cache->add($key, $value);
+ $this->_keyList->add($key);
+ if($this->_keyList->getCount() > $this->_cacheSize)
+ {
+ $oldestKey = $this->_keyList->removeAt(0);
+ $this->_cache->remove($oldestKey);
+ }
+ }
+} \ No newline at end of file