|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\cache\database; |
|
4
|
|
|
|
|
5
|
|
|
use Ubiquity\cache\system\ArrayCache; |
|
6
|
|
|
use Ubiquity\cache\CacheManager; |
|
7
|
|
|
|
|
8
|
|
|
abstract class DbCache { |
|
9
|
|
|
protected $cache; |
|
10
|
|
|
protected $config; |
|
11
|
|
|
public static $active=false; |
|
12
|
|
|
|
|
13
|
6 |
|
protected function getKey($query) { |
|
14
|
6 |
|
return \md5($query); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
13 |
|
public function __construct() { |
|
18
|
13 |
|
$this->cache=new ArrayCache(CacheManager::getCacheSubDirectory("queries"), ".query"); |
|
19
|
13 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Caches the given data with the given key (tableName+md5(condition)). |
|
23
|
|
|
* @param string $tableName |
|
24
|
|
|
* @param string $condition |
|
25
|
|
|
* @param array $result the datas to store |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract public function store($tableName, $condition, $result); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Fetches data stored for the given condition in table. |
|
31
|
|
|
* @param string $tableName |
|
32
|
|
|
* @param string $condition |
|
33
|
|
|
* @return mixed the cached datas |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract public function fetch($tableName, $condition); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Deletes the entry corresponding to $condition apply to $table |
|
39
|
|
|
* @param string $tableName |
|
40
|
|
|
* @param string $condition |
|
41
|
|
|
* @return boolean true if the entry is deleted |
|
42
|
|
|
*/ |
|
43
|
|
|
abstract public function delete($tableName, $condition); |
|
44
|
|
|
|
|
45
|
|
|
public function clear($matches="") { |
|
46
|
|
|
$this->cache->clear($matches); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function remove($key) { |
|
50
|
|
|
$this->cache->remove($key); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setActive($value=true) { |
|
54
|
|
|
self::$active=$value; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|