ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilXcache.php
Go to the documentation of this file.
1<?php
2require_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
79 public function flush()
80 {
81 $_SERVER["PHP_AUTH_USER"] = "xcache";
82 $_SERVER["PHP_AUTH_PW"] = "xcache";
83
84 xcache_clear_cache(XC_TYPE_VAR, 0);
85
86 return true;
87 }
88
89
95 public function serialize($value)
96 {
97 return serialize($value);
98 }
99
100
106 public function unserialize($serialized_value)
107 {
108 return unserialize($serialized_value);
109 }
110
111
115 protected function getActive()
116 {
117 $function_exists = function_exists('xcache_set');
118 $var_size = ini_get('xcache.var_size') != '0M';
119 $var_count = ini_get('xcache.var_count') > 0;
120 $api = (php_sapi_name() !== 'cli');
121
122 $active = $function_exists and $var_size and $var_count and $api;
123
124 return $active;
125 }
126
127
131 protected function getInstallable()
132 {
133 return function_exists('xcache_set');
134 }
135
136
140 public function getInfo()
141 {
142 if ($this->isActive()) {
143 return xcache_info(XC_TYPE_VAR, 0);
144 }
145 }
146
147
151 protected function getMemoryLimit()
152 {
153 return ini_get('xcache.var_size');
154 }
155
156
160 protected function getMinMemory()
161 {
162 return self::MIN_MEMORY;
163 }
164
170 protected function saveValid()
171 {
172 if ($this->isActive()) {
173 if ($this->valid_key_hash != md5(serialize($this->valid_keys))) {
174 $this->set('valid_keys', $this->serialize($this->valid_keys));
175 }
176 }
177 }
178
179
185 protected function readValid()
186 {
187 if ($this->isActive() && $this->isInstallable()) {
188 $this->valid_keys = $this->unserialize($this->get('valid_keys'));
189 $this->valid_key_hash = md5(serialize($this->valid_keys));
190 }
191 }
192
193 public function __destruct()
194 {
195 $this->saveValid();
196 }
197}
An exception for terminatinating execution or to throw for unit testing.
Class ilGlobalCacheService.
Class ilXcache.
const MIN_MEMORY
serialize($value)
exists($key)
__construct($serviceId, $component)
ilXcache constructor.
unserialize($serialized_value)
$key
Definition: croninfo.php:18
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']