* @link http://www.pradosoft.com/ * @copyright Copyright © 2005-2014 PradoSoft * @license http://www.pradosoft.com/license/ * @package Prado\Data\SqlMap\DataMapper */ namespace Prado\Data\SqlMap\DataMapper; /** * Allow different implementation of caching strategy. See TSqlMapFifoCache * for a first-in-first-out implementation. See TSqlMapLruCache for * a least-recently-used cache implementation. * * @author Wei Zhuo * @package Prado\Data\SqlMap\DataMapper * @since 3.1 */ abstract class TSqlMapCache implements ICache { protected $_keyList; protected $_cache; protected $_cacheSize = 100; protected $_cacheModel = null; /** * Create a new cache with limited cache size. * @param TSqlMapCacheModel $cacheModel. */ public function __construct($cacheModel=null) { $this->_cache = new TMap; $this->_keyList = new TList; $this->_cacheModel=$cacheModel; } /** * Maximum number of items to cache. Default size is 100. * @param int cache size. */ public function setCacheSize($value) { $this->_cacheSize=TPropertyValue::ensureInteger($value,100); } /** * @return int cache size. */ public function getCacheSize() { return $this->_cacheSize; } /** * @return object the object removed if exists, null otherwise. */ public function delete($key) { $object = $this->get($key); $this->_cache->remove($key); $this->_keyList->remove($key); return $object; } /** * Clears the cache. */ public function flush() { $this->_keyList->clear(); $this->_cache->clear(); } /** * @throws TSqlMapException not implemented. */ public function add($id,$value,$expire=0,$dependency=null) { throw new TSqlMapException('sqlmap_use_set_to_store_cache'); } }