Ubiquity  2.0.0
php rapid development framework
AbstractDataCache.php
Go to the documentation of this file.
1 <?php
7 
11 abstract class AbstractDataCache {
16  const PHP_TAG="<?php\n";
17 
18 
19  protected $_root;
20 
21  protected $postfix;
22 
23  public function __construct($root, $postfix=""){
24  $this->_root=$root;
25  $this->postfix=$postfix;
26  }
32  abstract public function exists($key);
33 
34  public function expired($key, $duration) {
35  if ($this->exists($key)) {
36  if (\is_int($duration) && $duration!==0) {
37  return \time() - $this->getTimestamp($key) > $duration;
38  } else {
39  return false;
40  }
41  } else {
42  return true;
43  }
44  }
45 
54  public function store($key, $code,$tag=null, $php=true) {
55  $content="";
56  if ($php)
57  $content=self::PHP_TAG;
58  $content.=$code . "\n";
59  $this->storeContent($key, $content,$tag);
60  }
61 
62  public function getRoot() {
63  return $this->_root;
64  }
65 
66  abstract protected function storeContent($key,$content,$tag);
67 
73  abstract public function fetch($key);
74 
80  abstract public function file_get_contents($key);
81 
88  abstract public function getTimestamp($key);
89 
93  abstract public function remove($key);
94 
98  abstract public function clear();
99 
100  abstract public function getCacheFiles($type);
101 
102  abstract public function clearCache($type);
103 
104  public function getCacheInfo(){
105  return "Cache system is an instance of <b>".\get_class($this)."</b>.";
106  }
107  abstract public function getEntryKey($key);
108 
109 }
getTimestamp($key)
Returns the timestamp of the last cache update for the given key.
fetch($key)
Fetches data stored for the given key.
Inspired by (c) Rasmus Schultz rasmus@mindplay.dk https://github.com/mindplay-dk/php-annotations ...
clear()
Clears all cache entries.
exists($key)
Check if annotation-data for the key has been stored.
file_get_contents($key)
return data stored for the given key.
store($key, $code, $tag=null, $php=true)
Caches the given data with the given key.
This class is responsible for storing Arrays in PHP files.