ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGlobalCacheService.php
Go to the documentation of this file.
1<?php
2
11abstract class ilGlobalCacheService {
12
16 protected $current_time = 0;
20 protected $valid_keys = array();
24 protected static $active = array();
28 protected static $installable = array();
32 protected $service_id = '';
36 protected $component = '';
44 protected $valid_key_hash = '';
45
46
54 self::$active[get_called_class()] = $this->getActive();
55 self::$installable[get_called_class()] = ($this->getInstallable() AND $this->checkMemory());
56 }
57
58
62 abstract protected function getActive();
63
64
68 abstract protected function getInstallable();
69
70
76 abstract public function unserialize($serialized_value);
77
78
84 abstract public function get($key);
85
86
94 abstract public function set($key, $serialized_value, $ttl = null);
95
96
102 abstract public function serialize($value);
103
104
108 public function getServiceId() {
109 return $this->service_id;
110 }
111
112
116 public function setServiceId($service_id) {
117 $this->service_id = $service_id;
118 }
119
120
124 public function getComponent() {
125 return $this->component;
126 }
127
128
132 public function setComponent($component) {
133 $this->component = $component;
134 }
135
136
140 public function isActive() {
141 return self::$active[get_called_class()];
142 }
143
144
148 public function isInstallable() {
149 return self::$installable[get_called_class()];
150 }
151
152
158 public function returnKey($key) {
159 return $str = $this->getServiceId() . '_' . $this->getComponent() . '_' . $key;
160 }
161
162
166 public function getInfo() {
167 return array();
168 }
169
170
175 if (!$this->getInstallable()) {
176 return 'Not installed';
177 }
178 if (!$this->checkMemory()) {
179 return 'Not enough Cache-Memory, set to at least ' . $this->getMinMemory() . 'M';
180 }
181
182 return 'Unknown reason';
183 }
184
185
189 protected function getMemoryLimit() {
190 return 9999;
191 }
192
193
197 protected function getMinMemory() {
198 return 0;
199 }
200
201
205 protected function checkMemory() {
206 $matches = array();
207 $memory_limit = $this->getMemoryLimit();
208 if (preg_match('/([0-9]*)([M|K])/uism', $memory_limit, $matches)) {
209 switch ($matches[2]) {
210 case 'M':
211 $memory_limit = $matches[1] * 1024 * 1024; // nnnM -> nnn MB
212 break;
213 case 'K':
214 $memory_limit = $matches[1] * 1024; // nnnK -> nnn KB
215 break;
216 }
217 } else {
218 $memory_limit = $memory_limit * 1024 * 1024; // nnnM -> nnn MB
219 }
220
221 return ($memory_limit >= $this->getMinMemory() * 1024 * 1024);
222 }
223
224
230 abstract public function exists($key);
231
232
238 abstract public function delete($key);
239
240
244 abstract public function flush();
245
246
250 public function setServiceType($service_type) {
251 $this->service_type = $service_type;
252 }
253
254
258 public function getServiceType() {
259 return $this->service_type;
260 }
261
262
273 public function setValid($key) {
274 $this->valid_keys[$key] = true;
275 }
276
288 public function setInvalid($key = null) {
289 if ($key !== NULL) {
290 unset($this->valid_keys[$key]);
291 } else {
292 unset($this->valid_keys);
293 }
294 }
295
296
307 public function isValid($key) {
308 return isset($this->valid_keys[$key]);
309 }
310}
An exception for terminatinating execution or to throw for unit testing.
Class ilGlobalCacheService.
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.