Ubiquity  2.3.10
php rapid development framework
TableCache.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
16 class TableCache extends DbCache {
17  protected $arrayCache;
18 
19  public function store($tableName, $condition, $result) {
20  $exists = $this->getCache ( $tableName );
21  $exists [$this->getKey ( $condition )] = $result;
22  $this->cache->store ( $tableName, "return " . UArray::asPhpArray ( $exists, "array" ) . ";" );
23  }
24 
25  public function getCache($tableName) {
26  if ($this->cache->exists ( $tableName ))
27  return $this->cache->fetch ( $tableName );
28  return [ ];
29  }
30 
31  protected function getArrayCache($tableName) {
32  if (isset ( $this->arrayCache [$tableName] ))
33  return $this->arrayCache [$tableName];
34  if ($this->cache->exists ( $tableName )) {
35  return $this->arrayCache [$tableName] = $this->cache->fetch ( $tableName );
36  }
37  return false;
38  }
39 
40  public function fetch($tableName, $condition) {
41  if ($cache = $this->getArrayCache ( $tableName )) {
42  $key = $this->getKey ( $condition );
43  if (isset ( $cache [$key] ))
44  return $cache [$key];
45  }
46  return false;
47  }
48 
49  public function delete($tableName, $condition) {
50  if ($cache = $this->getArrayCache ( $tableName )) {
51  $key = $this->getKey ( $condition );
52  if (isset ( $cache [$key] )) {
53  unset ( $cache [$key] );
54  $this->cache->store ( $tableName, "return " . UArray::asPhpArray ( $cache, "array" ) . ";" );
55  }
56  }
57  }
58 }
store($tableName, $condition, $result)
Definition: TableCache.php:19
Abstract class for database caching Ubiquity$DbCache This class is part of Ubiquity.
Definition: DbCache.php:20
Database cache systems.
Definition: DbCache.php:6
fetch($tableName, $condition)
Definition: TableCache.php:40
Cache Ubiquity$TableCache This class is part of Ubiquity.
Definition: TableCache.php:16
static asPhpArray($array, $prefix="", $depth=1, $format=false)
Definition: UArray.php:95