Passed
Push — master ( 3b5a7c...0f24e7 )
by Jean-Christophe
05:29
created

DbCache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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