ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 // incomplete flushing is not supported by APCu, an own implementation caused issues like https://mantis.ilias.de/view.php?id=28201
78 return function_exists('apcu_clear_cache') && apcu_clear_cache();
79 }
80
81
87 public function serialize($value)
88 {
89 return ($value);
90 }
91
92
98 public function unserialize($serialized_value)
99 {
100 return ($serialized_value);
101 }
102
103
107 public function getInfo()
108 {
109 $return = array();
110
111 $cache_info = apc_cache_info();
112
113 unset($cache_info['cache_list']);
114 unset($cache_info['slot_distribution']);
115
116 $return['__cache_info'] = array(
117 'apc.enabled' => ini_get('apc.enabled'),
118 'apc.shm_size' => ini_get('apc.shm_size'),
119 'apc.shm_segments' => ini_get('apc.shm_segments'),
120 'apc.gc_ttl' => ini_get('apc.gc_ttl'),
121 'apc.user_ttl' => ini_get('apc.ttl'),
122 'info' => $cache_info,
123 );
124
125 $cache_info = apc_cache_info();
126 foreach ($cache_info['cache_list'] as $dat) {
127 $key = $dat['key'];
128
129 if (preg_match('/' . $this->getServiceId() . '_' . $this->getComponent() . '/', $key)) {
130 $return[$key] = apc_fetch($key);
131 }
132 }
133
134 return $return;
135 }
136
137
138 protected function getActive()
139 {
140 return function_exists('apcu_store');
141 }
142
143
147 protected function getInstallable()
148 {
149 return function_exists('apcu_store');
150 }
151
152
156 protected function getMemoryLimit()
157 {
158 if (ilRuntime::getInstance()->isHHVM()) {
159 return $this->getMinMemory() . 'M';
160 }
161
162 return ini_get('apc.shm_size');
163 }
164
165
169 protected function getMinMemory()
170 {
171 return self::MIN_MEMORY;
172 }
173
174
178 public function isValid($key)
179 {
180 return true;
181 }
182}
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)
Definition: class.ilApc.php:98
const CACHE_ID
Definition: class.ilApc.php:17
getInstallable()
serialize($value)
Definition: class.ilApc.php:87
getMinMemory()
@inheritDoc
Class ilGlobalCacheService.
static getInstance()