blob: aabff1bd7d4209d13e216e003053e8f1c134fa57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?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 © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Data\SqlMap\DataMapper
*/
namespace Prado\Data\SqlMap\DataMapper;
use Prado\Caching\ICache;
use Prado\Collections\TList;
use Prado\Collections\TMap;
use Prado\TPropertyValue;
/**
* Allow different implementation of caching strategy. See <tt>TSqlMapFifoCache</tt>
* for a first-in-first-out implementation. See <tt>TSqlMapLruCache</tt> for
* a least-recently-used cache implementation.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @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');
}
}
|