ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilGlobalCacheService.php
Go to the documentation of this file.
1<?php
2
12{
13
17 protected $current_time = 0;
21 protected $valid_keys = array();
25 protected static $active = array();
29 protected static $installable = array();
33 protected $service_id = '';
37 protected $component = '';
45 protected $valid_key_hash = '';
46
47
53 {
56 self::$active[get_called_class()] = $this->getActive();
57 self::$installable[get_called_class()] = ($this->getInstallable() and $this->checkMemory());
58 }
59
60
64 abstract protected function getActive();
65
66
70 abstract protected function getInstallable();
71
72
78 abstract public function unserialize($serialized_value);
79
80
86 abstract public function get($key);
87
88
96 abstract public function set($key, $serialized_value, $ttl = null);
97
98
104 abstract public function serialize($value);
105
106
110 public function getServiceId()
111 {
112 return $this->service_id;
113 }
114
115
119 public function setServiceId($service_id)
120 {
121 $this->service_id = $service_id;
122 }
123
124
128 public function getComponent()
129 {
130 return $this->component;
131 }
132
133
137 public function setComponent($component)
138 {
139 $this->component = $component;
140 }
141
142
146 public function isActive()
147 {
148 return self::$active[get_called_class()];
149 }
150
151
155 public function isInstallable()
156 {
157 return self::$installable[get_called_class()];
158 }
159
160
166 public function returnKey($key)
167 {
168 return $str = $this->getServiceId() . '_' . $this->getComponent() . '_' . $key;
169 }
170
171
175 public function getInfo()
176 {
177 return array();
178 }
179
180
185 {
186 if (!$this->getInstallable()) {
187 return 'Not installed';
188 }
189 if (!$this->checkMemory()) {
190 return 'Not enough Cache-Memory, set to at least ' . $this->getMinMemory() . 'M';
191 }
192
193 return 'Unknown reason';
194 }
195
196
200 protected function getMemoryLimit()
201 {
202 return 9999;
203 }
204
205
209 protected function getMinMemory()
210 {
211 return 0;
212 }
213
214
218 protected function checkMemory()
219 {
220 $matches = array();
221 $memory_limit = $this->getMemoryLimit();
222 if (preg_match('/([0-9]*)([M|K])/uism', $memory_limit, $matches)) {
223 switch ($matches[2]) {
224 case 'M':
225 $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB
226 break;
227 case 'K':
228 $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB
229 break;
230 }
231 } else {
232 $memory_limit = $memory_limit * 1024 * 1024; // nnnM -> nnn MB
233 }
234
235 return ($memory_limit >= $this->getMinMemory() * 1024 * 1024);
236 }
237
238
244 abstract public function exists($key);
245
246
252 abstract public function delete($key);
253
254
260 abstract public function flush($complete = false);
261
262
267 {
268 $this->service_type = $service_type;
269 }
270
271
275 public function getServiceType()
276 {
277 return $this->service_type;
278 }
279
280
291 public function setValid($key)
292 {
293 $this->valid_keys[$key] = true;
294 }
295
307 public function setInvalid($key = null)
308 {
309 if ($key !== null) {
310 unset($this->valid_keys[$key]);
311 } else {
312 unset($this->valid_keys);
313 }
314 }
315
316
327 public function isValid($key)
328 {
329 return isset($this->valid_keys[$key]);
330 }
331}
An exception for terminatinating execution or to throw for unit testing.
Class ilGlobalCacheService.
flush($complete=false)
unserialize($serialized_value)
__construct($service_id, $component)
setValid($key)
Declare a key as valid.
setInvalid($key=null)
Set the key as invalid.
isValid($key)
Checks whether the cache key is valid or not.