ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  {
25  parent::__construct($serviceId, $component);
26  $this->readValid();
27  }
28 
29 
35  public function exists($key)
36  {
37  return xcache_isset($this->returnKey($key));
38  }
39 
40 
48  public function set($key, $serialized_value, $ttl = null)
49  {
50  return xcache_set($this->returnKey($key), $serialized_value, $ttl);
51  }
52 
53 
59  public function get($key)
60  {
61  return xcache_get($this->returnKey($key));
62  }
63 
64 
70  public function delete($key)
71  {
72  return xcache_unset($this->returnKey($key));
73  }
74 
75 
81  public function flush($complete = false)
82  {
83  $_SERVER["PHP_AUTH_USER"] = "xcache";
84  $_SERVER["PHP_AUTH_PW"] = "xcache";
85 
86  xcache_clear_cache(XC_TYPE_VAR, 0);
87 
88  return true;
89  }
90 
91 
97  public function serialize($value)
98  {
99  return serialize($value);
100  }
101 
102 
108  public function unserialize($serialized_value)
109  {
110  return unserialize($serialized_value);
111  }
112 
113 
117  protected function getActive()
118  {
119  $function_exists = function_exists('xcache_set');
120  $var_size = ini_get('xcache.var_size') != '0M';
121  $var_count = ini_get('xcache.var_count') > 0;
122  $api = (php_sapi_name() !== 'cli');
123 
124  $active = $function_exists and $var_size and $var_count and $api;
125 
126  return $active;
127  }
128 
129 
133  protected function getInstallable()
134  {
135  return function_exists('xcache_set');
136  }
137 
138 
142  public function getInfo()
143  {
144  if ($this->isActive()) {
145  return xcache_info(XC_TYPE_VAR, 0);
146  }
147  }
148 
149 
153  protected function getMemoryLimit()
154  {
155  return ini_get('xcache.var_size');
156  }
157 
158 
162  protected function getMinMemory()
163  {
164  return self::MIN_MEMORY;
165  }
166 
172  protected function saveValid()
173  {
174  if ($this->isActive()) {
175  if ($this->valid_key_hash != md5(serialize($this->valid_keys))) {
176  $this->set('valid_keys', $this->serialize($this->valid_keys));
177  }
178  }
179  }
180 
181 
187  protected function readValid()
188  {
189  if ($this->isActive() && $this->isInstallable()) {
190  $this->valid_keys = $this->unserialize($this->get('valid_keys'));
191  $this->valid_key_hash = md5(serialize($this->valid_keys));
192  }
193  }
194 
195  public function __destruct()
196  {
197  $this->saveValid();
198  }
199 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
exists($key)
Class ilGlobalCacheService.
serialize($value)
flush($complete=false)
unserialize($serialized_value)
Class ilXcache.
$key
Definition: croninfo.php:18
__construct($serviceId, $component)
ilXcache constructor.
const MIN_MEMORY