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

TableCache   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 5 1
A getCache() 0 5 2
A getArrayCache() 0 8 3
A fetch() 0 8 3
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