ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilXcache.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/GlobalCache/classes/class.ilGlobalCacheService.php');
3 
13 
14  const MIN_MEMORY = 32;
15 
16 
23  public function __construct($serviceId, $component) {
24  parent::__construct($serviceId, $component);
25  $this->readValid();
26  }
27 
28 
34  public function exists($key) {
35  return xcache_isset($this->returnKey($key));
36  }
37 
38 
46  public function set($key, $serialized_value, $ttl = null) {
47  return xcache_set($this->returnKey($key), $serialized_value, $ttl);
48  }
49 
50 
56  public function get($key) {
57  return xcache_get($this->returnKey($key));
58  }
59 
60 
66  public function delete($key) {
67  return xcache_unset($this->returnKey($key));
68  }
69 
70 
74  public function flush() {
75  $_SERVER["PHP_AUTH_USER"] = "xcache";
76  $_SERVER["PHP_AUTH_PW"] = "xcache";
77 
78  xcache_clear_cache(XC_TYPE_VAR, 0);
79 
80  return true;
81  }
82 
83 
89  public function serialize($value) {
90  return serialize($value);
91  }
92 
93 
99  public function unserialize($serialized_value) {
100  return unserialize($serialized_value);
101  }
102 
103 
107  protected function getActive() {
108  $function_exists = function_exists('xcache_set');
109  $var_size = ini_get('xcache.var_size') != '0M';
110  $var_count = ini_get('xcache.var_count') > 0;
111  $api = (php_sapi_name() !== 'cli');
112 
113  $active = $function_exists AND $var_size AND $var_count AND $api;
114 
115  return $active;
116  }
117 
118 
122  protected function getInstallable() {
123  return function_exists('xcache_set');
124  }
125 
126 
130  public function getInfo() {
131  if ($this->isActive()) {
132  return xcache_info(XC_TYPE_VAR, 0);
133  }
134  }
135 
136 
140  protected function getMemoryLimit() {
141  return ini_get('xcache.var_size');
142  }
143 
144 
148  protected function getMinMemory() {
149  return self::MIN_MEMORY;
150  }
151 
157  protected function saveValid() {
158  if ($this->isActive()) {
159  if ($this->valid_key_hash != md5(serialize($this->valid_keys))) {
160  $this->set('valid_keys', $this->serialize($this->valid_keys));
161  }
162  }
163  }
164 
165 
171  protected function readValid() {
172  if ($this->isActive() && $this->isInstallable()) {
173  $this->valid_keys = $this->unserialize($this->get('valid_keys'));
174  $this->valid_key_hash = md5(serialize($this->valid_keys));
175  }
176  }
177 
178  public function __destruct() {
179  $this->saveValid();
180  }
181 
182 }
183 
184 ?>
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
exists($key)
Class ilGlobalCacheService.
serialize($value)
unserialize($serialized_value)
Class ilXcache.
__construct($serviceId, $component)
ilXcache constructor.
const MIN_MEMORY