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,
132 $ilGlobalCache->initCachingService();
134 self::$instances[
$component] = $ilGlobalCache;
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);
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();
245 return ilMemcache::class;
247 return ilStaticCache::class;
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) {
350 if ($this->global_cache->isValid(
$key)) {
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();
Component logger with individual log levels by component id.
Class ilGlobalCacheSettings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllTypes(bool $only_available=true)
getInstallationFailureReason()
static setAvailableComponents(array $available_components)
static string $unique_service_id
__construct(int $service_type)
static lookupServiceClassName(int $service_type)
static array $available_types
isCacheServiceInstallable()
static ilGlobalCacheSettings $settings
flush(bool $complete=false)
setServiceType(int $service_type)
static setup(ilGlobalCacheSettings $ilGlobalCacheSettings)
static lookupServiceConfigName(int $service_type)
ilGlobalCacheService $global_cache
setComponent(string $component)
static array $available_components
static setSettings(ilGlobalCacheSettings $settings)
static getAllInstallableTypes()
static getActiveComponents()
static array $active_components
static getInstance(?string $component)
static array $type_per_component
static array $active_cache
static setActiveComponents(array $active_components)
static getAvailableComponents()
static log(string $message, int $log_level)
static generateServiceId()
if(empty($path)) $serviceName