Ubiquity  2.0.0
php rapid development framework
PhpFastCacheDriver.php
Go to the documentation of this file.
1 <?php
2 namespace Ubiquity\cache\system;
3 
7 
15  private $cacheInstance;
19  public function __construct($root,$postfix="",$cacheParams=[]) {
20  parent::__construct($root,$postfix);
21  $cacheType=$cacheParams['type'];
22  $defaultParams=['defaultTtl'=>86400,'itemDetailedDate'=>true];
23  $cacheParams=\array_merge($cacheParams,$defaultParams);
24  $this->cacheInstance = CacheManager::getInstance($cacheType,$cacheParams);
25  }
26 
32  public function exists($key) {
33  return $this->cacheInstance->hasItem($this->getRealKey($key));
34  }
35 
36  public function store($key, $code,$tag=null, $php=true) {
37  $this->storeContent($key, $code,$tag);
38  }
39 
46  protected function storeContent($key,$content,$tag) {
47  $key=$this->getRealKey($key);
48  $item=$this->cacheInstance->getItem($key);
49  $item->set($content);
50  $item->addTag($tag);
51  $this->cacheInstance->save($item);
52  }
53 
54  protected function getRealKey($key){
55  $key=\str_replace("/", "-", $key);
56  return \str_replace("\\", "-", $key);
57  }
58 
64  public function fetch($key) {
65  $result=$this->cacheInstance->getItem($this->getRealKey($key))->get();
66  return eval($result);
67  }
68 
74  public function file_get_contents($key) {
75  return $this->cacheInstance->getItem($this->getRealKey($key))->get();
76  }
77 
84  public function getTimestamp($key) {
85  $key=$this->getRealKey($key);
86  return $this->cacheInstance->getItem($key)->getModificationDate()->getTimestamp();
87  }
88 
89  public function remove($key) {
90  $key=$this->getRealKey($key);
91  $this->cacheInstance->deleteItem($this->getRealKey($key));
92  }
93 
94  public function clear() {
95  $this->cacheInstance->clear();
96  }
97 
98  protected function getCacheEntries($type){
99  return $this->cacheInstance->getItemsByTag($type);
100  }
101 
102  public function getCacheFiles($type){
103  $result=[];
104  $entries=$this->getCacheEntries($type);
105 
106  foreach ($entries as $entry) {
107  $key=$entry->getKey();
108  $result[]=new CacheFile(\ucfirst($type),$key,$entry->getCreationDate()->getTimestamp(),"",$key);
109  }
110  if(\sizeof($result)===0)
111  $result[]=new CacheFile(\ucfirst($type),"","","");
112  return $result;
113  }
114 
115  public function clearCache($type){
116  $this->cacheInstance->deleteItemsByTag($type);
117  }
118 
119  public function getCacheInfo(){
120  return parent::getCacheInfo()."<br>Driver name : <b>".$this->cacheInstance->getDriverName()."</b>";
121  }
122 
123  public function getEntryKey($key){
124  return $this->cacheInstance->getItem($this->getRealKey($key))->getKey();
125  }
126 }
fetch($key)
Fetches data stored for the given key.
exists($key)
Check if annotation-data for the key has been stored.
storeContent($key, $content, $tag)
Caches the given data with the given key.
Inspired by (c) Rasmus Schultz rasmus@mindplay.dk https://github.com/mindplay-dk/php-annotations ...
store($key, $code, $tag=null, $php=true)
file_get_contents($key)
return data stored for the given key.
This class is responsible for storing Arrays in PHP files.
getTimestamp($key)
Returns the timestamp of the last cache update for the given key.
__construct($root, $postfix="", $cacheParams=[])
Initializes the cache-provider.
This class is responsible for storing values with PhpFastCache.