Ubiquity  2.0.3
php rapid development framework
TableCache.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class TableCache extends DbCache {
8  protected $arrayCache;
9 
10  public function store($tableName, $condition, $result) {
11  $exists=$this->getCache($tableName);
12  $exists[$this->getKey($condition)]=$result;
13  $this->cache->store($tableName, "return " . UArray::asPhpArray($exists, "array") . ";");
14  }
15 
16  public function getCache($tableName) {
17  if ($this->cache->exists($tableName))
18  return $this->cache->fetch($tableName);
19  return [ ];
20  }
21 
22  protected function getArrayCache($tableName) {
23  if (isset($this->arrayCache[$tableName]))
24  return $this->arrayCache[$tableName];
25  if ($this->cache->exists($tableName)) {
26  return $this->arrayCache[$tableName]=$this->cache->fetch($tableName);
27  }
28  return false;
29  }
30 
31  public function fetch($tableName, $condition) {
32  if ($cache=$this->getArrayCache($tableName)) {
33  $key=$this->getKey($condition);
34  if (isset($cache[$key]))
35  return $cache[$key];
36  }
37  return false;
38  }
39 
40  public function delete($tableName, $condition){
41  if ($cache=$this->getArrayCache($tableName)) {
42  $key=$this->getKey($condition);
43  if (isset($cache[$key])){
44  unset($cache[$key]);
45  $this->cache->store($tableName, "return " . UArray::asPhpArray($cache, "array") . ";");
46  }
47  }
48  }
49 }
store($tableName, $condition, $result)
Definition: TableCache.php:10
fetch($tableName, $condition)
Definition: TableCache.php:31
static asPhpArray($array, $prefix="", $depth=1, $format=false)
Definition: UArray.php:53