ILIAS  release_8 Revision v8.24
class.ilGlobalCacheService.php
Go to the documentation of this file.
1<?php
2
26{
27 protected int $current_time = 0;
28 protected array $valid_keys = array();
29 protected static array $active = array();
30 protected static array $installable = array();
31 protected string $service_id = '';
32 protected string $component = '';
34 protected string $valid_key_hash = '';
35
39 public function __construct(string $service_id, string $component)
40 {
41 $this->setComponent($component);
42 $this->setServiceId($service_id);
43 self::$active[static::class] = $this->getActive();
44 self::$installable[static::class] = ($this->getInstallable() && $this->checkMemory());
45 }
46
47 abstract protected function getActive(): bool;
48
49 abstract protected function getInstallable(): bool;
50
55 abstract public function unserialize($serialized_value);
56
60 abstract public function get(string $key);
61
65 abstract public function set(string $key, $serialized_value, int $ttl = null): bool;
66
71 abstract public function serialize($value);
72
73 public function getServiceId(): string
74 {
75 return $this->service_id;
76 }
77
78 public function setServiceId(string $service_id): void
79 {
80 $this->service_id = $service_id;
81 }
82
83 public function getComponent(): string
84 {
85 return $this->component;
86 }
87
88 public function setComponent(string $component): void
89 {
90 $this->component = $component;
91 }
92
93 public function isActive(): bool
94 {
95 return self::$active[static::class];
96 }
97
98 public function isInstallable(): bool
99 {
100 return self::$installable[static::class];
101 }
102
103 public function returnKey(string $key): string
104 {
105 return $this->getServiceId() . '_' . $this->getComponent() . '_' . $key;
106 }
107
108 public function getInfo(): array
109 {
110 return array();
111 }
112
113 public function getInstallationFailureReason(): string
114 {
115 if (!$this->getInstallable()) {
116 return 'Not installed';
117 }
118 if (!$this->checkMemory()) {
119 return 'Not enough Cache-Memory, set to at least ' . $this->getMinMemory() . 'M';
120 }
121
122 return 'Unknown reason';
123 }
124
125 protected function getMemoryLimit(): string
126 {
127 return '9999M';
128 }
129
130 protected function getMinMemory(): int
131 {
132 return 0;
133 }
134
135 protected function checkMemory(): bool
136 {
137 $matches = [];
138 $memory_limit = $this->getMemoryLimit();
139 if (preg_match('#(\d*)([M|K])#uim', $memory_limit, $matches)) {
140 if ($matches[2] === 'M') {
141 $memory_limit = $matches[1] * 1024 * 1024;
142 } elseif ($matches[2] === 'K') {
143 $memory_limit = $matches[1] * 1024;
144 }
145 } else {
146 $memory_limit *= 1024 * 1024; // nnnM -> nnn MB
147 }
148
149 return ($memory_limit >= $this->getMinMemory() * 1024 * 1024);
150 }
151
152 abstract public function exists(string $key): bool;
153
154 abstract public function delete(string $key): bool;
155
156 abstract public function flush(bool $complete = false): bool;
157
158 public function setServiceType(int $service_type): void
159 {
160 $this->service_type = $service_type;
161 }
162
163 public function getServiceType(): int
164 {
165 return $this->service_type;
166 }
167
168 public function setValid(string $key): void
169 {
170 $this->valid_keys[$key] = true;
171 }
172
173 public function isValid(string $key): bool
174 {
175 return isset($this->valid_keys[$key]);
176 }
177}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setServiceId(string $service_id)
flush(bool $complete=false)
unserialize($serialized_value)
isValid(string $key)
Checks whether the cache key is valid or not.
setValid(string $key)
Declare a key as valid.
__construct(string $service_id, string $component)
ilGlobalCacheService constructor.
exists(string $key)
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