Completed
Push — master ( 25576f...77f108 )
by Jean-Christophe
02:06
created

TableCache::fetch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace micro\cache\database;
4
use micro\utils\JArray;
5
6
class TableCache extends DbCache{
7
	protected $arrayCache;
8
9
	public function store($tableName,$condition,$result){
10
		$exists=$this->getCache($tableName);
11
		$exists[$this->getKey($condition)]=$result;
12
		$this->cache->store($tableName,"return ".JArray::asPhpArray($exists,"array").";");
13
	}
14
15
	public function getCache($tableName){
16
		if($this->cache->exists($tableName))
17
			return $this->cache->fetch($tableName);
18
		return [];
19
	}
20
21
	protected function getArrayCache($tableName){
22
		if(isset($this->arrayCache[$tableName]))
23
			return $this->arrayCache[$tableName];
24
		if($this->cache->exists($tableName)){
25
				return $this->arrayCache[$tableName]=$this->cache->fetch($tableName);
26
		}
27
		return false;
28
	}
29
30
	public function fetch($tableName,$condition){
31
		if($cache=$this->getArrayCache($tableName)){
32
			$key=$this->getKey($condition);
33
			if(isset($cache[$key]))
34
				return $cache[$key];
35
		}
36
		return false;
37
	}
38
}
39