Ubiquity  2.0.2
php rapid development framework
AbstractDataCache.php
Go to the documentation of this file.
1 <?php
7 
9 
13 abstract class AbstractDataCache {
18  const PHP_TAG="<?php\n";
19 
20 
21  protected $_root;
22 
23  protected $postfix;
24 
25  public function __construct($root, $postfix=""){
26  $this->_root=$root;
27  $this->postfix=$postfix;
28  }
34  abstract public function exists($key);
35 
36  public function expired($key, $duration) {
37  if ($this->exists($key)) {
38  if (\is_int($duration) && $duration!==0) {
39  return \time() - $this->getTimestamp($key) > $duration;
40  } else {
41  return false;
42  }
43  } else {
44  return true;
45  }
46  }
47 
56  public function store($key, $code,$tag=null, $php=true) {
57  $content="";
58  if ($php)
59  $content=self::PHP_TAG;
60  $content.=$code . "\n";
61  $this->storeContent($key, $content,$tag);
62  }
63 
64  public function getRoot() {
65  return $this->_root;
66  }
67 
68  abstract protected function storeContent($key,$content,$tag);
69 
75  abstract public function fetch($key);
76 
82  abstract public function file_get_contents($key);
83 
90  abstract public function getTimestamp($key);
91 
95  abstract public function remove($key);
96 
100  abstract public function clear();
101 
102  abstract public function getCacheFiles($type);
103 
104  abstract public function clearCache($type);
105 
106  public function getCacheInfo(){
107  return "Cache system is an instance of <b>".\get_class($this)."</b>.";
108  }
109  abstract public function getEntryKey($key);
110 
111 }
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.