Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
PhpFastCacheDriver.php
Go to the documentation of this file.
1<?php
2
4
6use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
7use Phpfastcache\CacheManager;
8
24
28 public function __construct($root, $postfix = "", $cacheParams = [ ]) {
29 parent::__construct ( $root, $postfix );
30 $cacheType = $cacheParams ['type'] ?? 'Files';
31 $configClass = '\\Phpfastcache\\Drivers\\' . \ucfirst ( $cacheType ) . '\\Config';
32 unset ( $cacheParams ['type'] );
33 $defaultParams = [ 'defaultTtl' => 86400,'itemDetailedDate' => true ];
34 $cacheParams = \array_merge ( $defaultParams, $cacheParams );
35 $this->cacheInstance = CacheManager::getInstance ( $cacheType, new $configClass ( $cacheParams ) );
36 }
37
44 public function exists($key) {
45 return $this->cacheInstance->hasItem ( $this->getRealKey ( $key ) );
46 }
47
48 public function store($key, $content, $tag = null) {
49 $key = $this->getRealKey ( $key );
50 $item = $this->cacheInstance->getItem ( $key );
51 $item->set ( $content );
52 if ($tag != null) {
53 $item->addTag ( $tag );
54 }
55 $this->cacheInstance->save ( $item );
56 }
57
58 protected function getRealKey($key) {
59 return \str_replace ( [ '\\','/' ], '-', $key );
60 }
61
68 public function fetch($key) {
69 return $this->cacheInstance->getItem ( $this->getRealKey ( $key ) )->get ();
70 }
71
78 public function file_get_contents($key) {
79 return $this->cacheInstance->getItem ( $this->getRealKey ( $key ) )->get ();
80 }
81
88 public function getTimestamp($key) {
89 return $this->cacheInstance->getItem ( $this->getRealKey ( $key ) )->getModificationDate ()->getTimestamp ();
90 }
91
92 public function remove($key) {
93 $this->cacheInstance->deleteItem ( $this->getRealKey ( $key ) );
94 }
95
96 public function clear() {
97 $this->cacheInstance->clear ();
98 }
99
100 protected function getCacheEntries($type) {
101 return $this->cacheInstance->getItemsByTag ( $type );
102 }
103
104 public function getCacheFiles($type) {
105 $result = [ ];
106 $entries = $this->getCacheEntries ( $type );
107
108 foreach ( $entries as $entry ) {
109 $key = $entry->getKey ();
110 $result [] = new CacheFile ( \ucfirst ( $type ), $key, $entry->getCreationDate ()->getTimestamp (), "", $key );
111 }
112 if (\count ( $result ) === 0)
113 $result [] = new CacheFile ( \ucfirst ( $type ), "", "", "" );
114 return $result;
115 }
116
117 public function clearCache($type) {
118 $this->cacheInstance->deleteItemsByTag ( $type );
119 }
120
121 public function getCacheInfo() {
122 return parent::getCacheInfo () . "<br>Driver name : <b>" . $this->cacheInstance->getDriverName () . "</b>";
123 }
124
125 public function getEntryKey($key) {
126 return $this->cacheInstance->getItem ( $this->getRealKey ( $key ) )->getKey ();
127 }
128}
This class is responsible for storing Arrays in PHP files.
This class is responsible for storing values with PhpFastCache.
file_get_contents($key)
return data stored for the given key.
fetch($key)
Fetches data stored for the given key.
__construct($root, $postfix="", $cacheParams=[])
Initializes the cache-provider.
exists($key)
Check if annotation-data for the key has been stored.
store($key, $content, $tag=null)
Caches the given data with the given key.
getTimestamp($key)
Returns the timestamp of the last cache update for the given key.