Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RedisCacheDriver.php
Go to the documentation of this file.
1<?php
2
4
6
22
26 public function __construct($root, $postfix = "", $cacheParams = [ ]) {
27 parent::__construct ( $root, $postfix );
28 $defaultParams = [ 'server' => '0.0.0.0','port' => 6379,'persistent' => true,'serializer' => \Redis::SERIALIZER_PHP ];
29 $cacheParams = \array_merge ( $defaultParams, $cacheParams );
30 $this->cacheInstance = new \Redis ();
31 $connect = 'connect';
32 if ($cacheParams ['persistent'] ?? true) {
33 $connect = 'pconnect';
34 }
35 $this->cacheInstance->{$connect} ( $cacheParams ['server'], $cacheParams ['port'] );
36 if (isset ( $cacheParams ['serializer'] )) {
37 $this->cacheInstance->setOption ( \Redis::OPT_SERIALIZER, $cacheParams ['serializer'] );
38 }
39 }
40
41 public function setSerializer($serializer) {
42 $this->cacheInstance->setOption ( \Redis::OPT_SERIALIZER, $serializer );
43 }
44
51 public function exists($key) {
52 return $this->cacheInstance->exists ( $this->getRealKey ( $key ) );
53 }
54
55 public function store($key, $content, $tag = null) {
56 $this->cacheInstance->set ( $this->getRealKey ( $key ), $content );
57 }
58
59 protected function getRealKey($key) {
60 return \str_replace ( [ '/','\\' ], "-", $key );
61 }
62
69 public function fetch($key) {
70 return $this->cacheInstance->get ( $this->getRealKey ( $key ) );
71 }
72
79 public function file_get_contents($key) {
80 return $this->cacheInstance->get ( $this->getRealKey ( $key ) );
81 }
82
89 public function getTimestamp($key) {
90 return $this->cacheInstance->ttl ( $this->getRealKey ( $key ) );
91 }
92
93 public function remove($key) {
94 $this->cacheInstance->delete ( $this->getRealKey ( $key ) );
95 }
96
97 public function clear() {
98 $this->cacheInstance->flushAll ();
99 }
100
101 public function getCacheFiles($type) {
102 $result = [ ];
103 $keys = $this->cacheInstance->keys ( $type );
104
105 foreach ( $keys as $key ) {
106 $ttl = $this->cacheInstance->ttl ( $key );
107 $result [] = new CacheFile ( \ucfirst ( $type ), $key, $ttl, "", $key );
108 }
109 if (\count ( $result ) === 0)
110 $result [] = new CacheFile ( \ucfirst ( $type ), "", "", "" );
111 return $result;
112 }
113
114 public function clearCache($type) {
115 $keys = $this->cacheInstance->keys ( $type );
116 foreach ( $keys as $key ) {
117 $this->cacheInstance->delete ( $key );
118 }
119 }
120
121 public function getCacheInfo() {
122 return parent::getCacheInfo () . "<br>Driver name : <b>" . \Redis::class . "</b>";
123 }
124
125 public function getEntryKey($key) {
126 return $this->getRealKey ( $key );
127 }
128}
This class is responsible for storing Arrays in PHP files.
This class is responsible for storing values with Redis.
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.