29 public const MSG =
'Global Cache not active, can not access cache';
90 protected static array
$types = array(
106 self::COMP_TPL_BLOCKS,
107 self::COMP_TPL_VARIABLES,
109 self::COMP_GLOBAL_SCREEN,
128 if (!isset(self::$instances[$component])) {
131 $ilGlobalCache->setComponent($component);
132 $ilGlobalCache->initCachingService();
134 self::$instances[
$component] = $ilGlobalCache;
142 self::generateServiceId();
146 protected function initCachingService():
void 158 $this->global_cache = $ilGlobalCacheService;
170 $ilLog = $DIC[\ilLog::class];
171 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
172 $function = $backtrace[1][
'function'];
173 $class = $backtrace[1][
'class'];
175 $ilLog->alert($class .
'::' . $function .
'(): ' . $message);
182 if (!isset(self::$unique_service_id)) {
183 $raw_service_id =
'_';
184 if (defined(
'CLIENT_ID')) {
187 self::$unique_service_id = substr(md5($raw_service_id), 0, 6);
189 return self::$unique_service_id;
192 public static function flushAll():
void 198 foreach (self::$types as
$type) {
205 $serviceName .
' returned status ' . ($returned ?
'ok' :
'failure'),
215 foreach (self::getAllTypes() as
$type) {
216 if ($type->isCacheServiceInstallable()) {
224 public static function getAllTypes(
bool $only_available =
true): array
227 foreach (self::$types as
$type) {
228 if ($only_available && !in_array($type, self::$available_types)) {
231 $obj =
new self(
$type);
232 $obj->initCachingService();
233 $types[
$type] = $obj;
241 switch ($service_type) {
244 case self::TYPE_MEMCACHED:
245 return ilMemcache::class;
247 return ilStaticCache::class;
253 switch ($service_type) {
256 case self::TYPE_MEMCACHED:
268 if (isset(self::$active_cache[
$c]) && self::$active_cache[$c] !== null) {
269 return self::$active_cache[
$c];
272 self::$active_cache[
$c] =
false;
278 self::$active_cache[
$c] =
false;
283 $isActive = $this->global_cache->isActive();
284 self::log(
'component ' . $c .
', service is active: ' 286 self::$active_cache[
$c] = $isActive;
293 return $this->global_cache->isValid($key);
298 return count(self::getAllInstallableTypes()) > 0;
303 return $this->global_cache->isInstallable();
308 return $this->global_cache->getInstallationFailureReason();
316 if (!$this->global_cache->isActive()) {
320 return $this->global_cache->exists($key);
327 public function set(
string $key, $value,
int $ttl = null):
bool 333 $this->global_cache->setValid($key);
335 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
342 public function get(
string $key)
347 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
348 if ($unserialized_return) {
349 $service_name =
' [' . self::lookupServiceClassName($this->
getServiceType()) .
']';
350 if ($this->global_cache->isValid($key)) {
352 $key .
' from component ' . $this->
getComponent() . $service_name,
356 return $unserialized_return;
359 $key .
' from component ' . $this->
getComponent() .
' is invalid' . $service_name,
368 public function delete(
string $key):
bool 374 return $this->global_cache->delete($key);
380 public function flush(
bool $complete =
false): bool
382 if ($this->global_cache->isActive()) {
383 return $this->global_cache->flush($complete);
391 return $this->global_cache->getInfo();
436 return self::$active_components;
446 return self::$available_components;
setServiceType(int $service_type)
if(empty($path)) $serviceName
static setActiveComponents(array $active_components)
static setAvailableComponents(array $available_components)
static getAllInstallableTypes()
Class ilGlobalCacheSettings.
static setup(ilGlobalCacheSettings $ilGlobalCacheSettings)
static array $available_components
flush(bool $complete=false)
Component logger with individual log levels by component id.
static log(string $message, int $log_level)
static generateServiceId()
static array $active_cache
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isCacheServiceInstallable()
static lookupServiceClassName(int $service_type)
static getAvailableComponents()
ilGlobalCacheService $global_cache
static array $type_per_component
getInstallationFailureReason()
static getAllTypes(bool $only_available=true)
static lookupServiceConfigName(int $service_type)
__construct(int $service_type)
static ilGlobalCacheSettings $settings
static getActiveComponents()
static array $active_components
static array $available_types
setComponent(string $component)
static setSettings(ilGlobalCacheSettings $settings)
static getInstance(?string $component)
static string $unique_service_id