From 90b5141367db5fcac9ba72042278556612b5dc3f Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 20 Jan 2015 22:02:33 +0100 Subject: One class per file: framework/Data --- .../Data/SqlMap/DataMapper/TSqlMapLruCache.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php (limited to 'framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php') diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php new file mode 100644 index 00000000..e34cad84 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php @@ -0,0 +1,51 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * Least recently used cache implementation, removes + * object that was accessed last when the cache is full. + * + * @author Wei Zhuo + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapLruCache extends TSqlMapCache +{ + /** + * @return mixed Gets a cached object with the specified key. + */ + public function get($key) + { + if($this->_keyList->contains($key)) + { + $this->_keyList->remove($key); + $this->_keyList->add($key); + return $this->_cache->itemAt($key); + } + } + + /** + * Stores a value identified by a key into cache. + * The expire and dependency parameters are ignored. + * @param string the key identifying the value to be cached + * @param mixed the value to be cached + */ + 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 -- cgit v1.2.3