ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilApc.php
Go to the documentation of this file.
1<?php
2
3require_once('./Services/GlobalCache/classes/class.ilGlobalCacheService.php');
4require_once('./Services/Environment/classes/class.ilRuntime.php');
5
15{
16 const MIN_MEMORY = 16;
17 const CACHE_ID = 'user';
18
19
25 public function exists($key)
26 {
27 if (function_exists('apcu_exists')) {
28 return apcu_exists($this->returnKey($key));
29 } else {
30 return apcu_fetch($this->returnKey($key));
31 }
32 }
33
34
42 public function set($key, $serialized_value, $ttl = 0)
43 {
44 return apcu_store($this->returnKey($key), $serialized_value, $ttl);
45 }
46
47
53 public function get($key)
54 {
55 return apcu_fetch($this->returnKey($key));
56 }
57
58
64 public function delete($key)
65 {
66 return apcu_delete($this->returnKey($key));
67 }
68
69
75 public function flush($complete = false)
76 {
77 if ($complete) {
78 return apcu_clear_cache();
79 }
80
81 $key_prefix = $this->returnKey('');
82 $apcu_iterator = new APCUIterator();
83 $apcu_iterator->rewind();
84 while ($current_key = $apcu_iterator->key()) {
85 // "begins with"
86 if (substr($current_key, 0, strlen($key_prefix)) === $key_prefix) {
87 $this->delete($current_key);
88 }
89 $apcu_iterator->next();
90 }
91 return true;
92 }
93
94
100 public function serialize($value)
101 {
102 return ($value);
103 }
104
105
111 public function unserialize($serialized_value)
112 {
113 return ($serialized_value);
114 }
115
116
120 public function getInfo()
121 {
122 $return = array();
123
124 $cache_info = apc_cache_info();
125
126 unset($cache_info['cache_list']);
127 unset($cache_info['slot_distribution']);
128
129 $return['__cache_info'] = array(
130 'apc.enabled' => ini_get('apc.enabled'),
131 'apc.shm_size' => ini_get('apc.shm_size'),
132 'apc.shm_segments' => ini_get('apc.shm_segments'),
133 'apc.gc_ttl' => ini_get('apc.gc_ttl'),
134 'apc.user_ttl' => ini_get('apc.ttl'),
135 'info' => $cache_info,
136 );
137
138 $cache_info = apc_cache_info();
139 foreach ($cache_info['cache_list'] as $dat) {
140 $key = $dat['key'];
141
142 if (preg_match('/' . $this->getServiceId() . '_' . $this->getComponent() . '/', $key)) {
143 $return[$key] = apc_fetch($key);
144 }
145 }
146
147 return $return;
148 }
149
150
151 protected function getActive()
152 {
153 return function_exists('apcu_store');
154 }
155
156
160 protected function getInstallable()
161 {
162 return function_exists('apcu_store');
163 }
164
165
169 protected function getMemoryLimit()
170 {
171 if (ilRuntime::getInstance()->isHHVM()) {
172 return $this->getMinMemory() . 'M';
173 }
174
175 return ini_get('apc.shm_size');
176 }
177
178
182 protected function getMinMemory()
183 {
184 return self::MIN_MEMORY;
185 }
186
187
191 public function isValid($key)
192 {
193 return true;
194 }
195}
An exception for terminatinating execution or to throw for unit testing.
Class ilApc.
Definition: class.ilApc.php:15
isValid($key)
Checks whether the cache key is valid or not.This method exists only for legacy reasons and has only ...
exists($key)
Definition: class.ilApc.php:25
getActive()
getMemoryLimit()
flush($complete=false)
Definition: class.ilApc.php:75
const MIN_MEMORY
Definition: class.ilApc.php:16
unserialize($serialized_value)
const CACHE_ID
Definition: class.ilApc.php:17
getInstallable()
serialize($value)
getMinMemory()
@inheritDoc
Class ilGlobalCacheService.
static getInstance()
$key
Definition: croninfo.php:18