ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilGlobalCacheService.php
Go to the documentation of this file.
1 <?php
2 
11 abstract class ilGlobalCacheService
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  {
54  $this->setComponent($component);
55  $this->setServiceId($service_id);
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 
258  abstract public function flush();
259 
260 
264  public function setServiceType($service_type)
265  {
266  $this->service_type = $service_type;
267  }
268 
269 
273  public function getServiceType()
274  {
275  return $this->service_type;
276  }
277 
278 
289  public function setValid($key)
290  {
291  $this->valid_keys[$key] = true;
292  }
293 
305  public function setInvalid($key = null)
306  {
307  if ($key !== null) {
308  unset($this->valid_keys[$key]);
309  } else {
310  unset($this->valid_keys);
311  }
312  }
313 
314 
325  public function isValid($key)
326  {
327  return isset($this->valid_keys[$key]);
328  }
329 }
isValid($key)
Checks whether the cache key is valid or not.
__construct($service_id, $component)
Class ilGlobalCacheService.
setValid($key)
Declare a key as valid.
Create styles array
The data for the language used.
setInvalid($key=null)
Set the key as invalid.
unserialize($serialized_value)
$key
Definition: croninfo.php:18