ILIAS  release_8 Revision v8.24
class.ilApc.php
Go to the documentation of this file.
1<?php
2
26{
30 private const MIN_MEMORY = 16;
31
32 public function exists(string $key): bool
33 {
34 if (function_exists('apcu_exists')) {
35 return apcu_exists($this->returnKey($key));
36 }
37 return (bool) apcu_fetch($this->returnKey($key));
38 }
39
40 public function set(string $key, $serialized_value, int $ttl = null): bool
41 {
42 return apcu_store($this->returnKey($key), $serialized_value, $ttl);
43 }
44
48 public function get(string $key)
49 {
50 return apcu_fetch($this->returnKey($key));
51 }
52
56 public function delete(string $key): bool
57 {
58 return apcu_delete($this->returnKey($key));
59 }
60
61 public function flush(bool $complete = false): bool
62 {
63 // incomplete flushing is not supported by APCu, an own implementation coused issues like https://mantis.ilias.de/view.php?id=28201
64 return function_exists('apcu_clear_cache') && apcu_clear_cache();
65 }
66
71 public function serialize($value)
72 {
73 return ($value);
74 }
75
80 public function unserialize($serialized_value)
81 {
82 return ($serialized_value);
83 }
84
85 public function getInfo(): array
86 {
87 $return = array();
88
89 $cache_info = apc_cache_info();
90
91 unset($cache_info['cache_list']);
92 unset($cache_info['slot_distribution']);
93
94 $return['__cache_info'] = array(
95 'apc.enabled' => ini_get('apc.enabled'),
96 'apc.shm_size' => ini_get('apc.shm_size'),
97 'apc.shm_segments' => ini_get('apc.shm_segments'),
98 'apc.gc_ttl' => ini_get('apc.gc_ttl'),
99 'apc.user_ttl' => ini_get('apc.ttl'),
100 'info' => $cache_info,
101 );
102
103 $cache_info = apc_cache_info();
104 foreach ($cache_info['cache_list'] as $dat) {
105 $key = $dat['key'];
106
107 if (preg_match('/' . $this->getServiceId() . '_' . $this->getComponent() . '/', $key)) {
108 $return[$key] = apc_fetch($key);
109 }
110 }
111
112 return $return;
113 }
114
115 protected function getActive(): bool
116 {
117 return function_exists('apcu_store');
118 }
119
120 protected function getInstallable(): bool
121 {
122 return function_exists('apcu_store');
123 }
124
125 protected function getMemoryLimit(): string
126 {
127 if (ilRuntime::getInstance()->isHHVM()) {
128 return $this->getMinMemory() . 'M';
129 }
130
131 return ini_get('apc.shm_size');
132 }
133
137 protected function getMinMemory(): int
138 {
139 return self::MIN_MEMORY;
140 }
141
145 public function isValid(string $key): bool
146 {
147 return true;
148 }
149}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilApc.php:26
flush(bool $complete=false)
Definition: class.ilApc.php:61
getActive()
getMemoryLimit()
const MIN_MEMORY
Definition: class.ilApc.php:30
unserialize($serialized_value)
Definition: class.ilApc.php:80
getInstallable()
serialize($value)
Definition: class.ilApc.php:71
isValid(string $key)
Checks whether the cache key is valid or not.
getMinMemory()
@inheritDoc
getInfo()
Definition: class.ilApc.php:85
exists(string $key)
Definition: class.ilApc.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193