ILIAS  release_7 Revision v7.30-3-g800a261c036
ilGlobalCache Class Reference

Class ilGlobalCache. More...

+ Collaboration diagram for ilGlobalCache:

Public Member Functions

 isActive ()
 
 isValid ($key)
 
 isInstallable ()
 
 isCacheServiceInstallable ()
 
 getInstallationFailureReason ()
 
 exists ($key)
 
 set ($key, $value, $ttl=null)
 
 get ($key)
 
 delete ($key)
 
 flush ($complete=false)
 
 getInfo ()
 
 setComponent ($component)
 
 getComponent ()
 
 setActive ($active)
 
 getActive ()
 
 setServiceType ($service_type)
 
 getServiceType ()
 

Static Public Member Functions

static setup (ilGlobalCacheSettings $ilGlobalCacheSettings)
 
static getInstance ($component)
 
static log ($message, $log_level)
 
static getAllInstallableTypes ()
 
static getAllTypes ($only_available=true)
 
static lookupServiceClassName ($service_type)
 
static lookupServiceConfigName (int $service_type)
 
static getSettings ()
 
static setSettings ($settings)
 
static getActiveComponents ()
 
static setActiveComponents ($active_components)
 
static getAvailableComponents ()
 
static setAvailableComponents ($available_components)
 

Data Fields

const MSG = 'Global Cache not active, can not access cache'
 
const ACTIVE = true
 
const TYPE_STATIC = 0
 
const TYPE_XCACHE = 1
 
const TYPE_MEMCACHED = 2
 
const TYPE_APC = 3
 
const TYPE_FALLBACK = self::TYPE_STATIC
 
const COMP_CLNG = 'clng'
 
const COMP_OBJ_DEF = 'obj_def'
 
const COMP_TEMPLATE = 'tpl'
 
const COMP_ILCTRL = 'ilctrl'
 
const COMP_PLUGINS = 'plugins'
 
const COMP_COMPONENT = 'comp'
 
const COMP_RBAC_UA = 'rbac_ua'
 
const COMP_EVENTS = 'events'
 
const COMP_TPL_BLOCKS = 'tpl_blocks'
 
const COMP_TPL_VARIABLES = 'tpl_variables'
 
const COMP_GLOBAL_SCREEN = 'global_screen'
 

Protected Member Functions

 __construct ($service_type)
 
 checkSettings ()
 

Static Protected Member Functions

static generateServiceId ()
 

Protected Attributes

 $global_cache
 
 $component
 
 $active = true
 
 $service_type = ilGlobalCache::TYPE_STATIC
 

Static Protected Attributes

static $types
 
static $available_types
 
static $active_components = array()
 
static $available_components
 
static $type_per_component = array()
 
static $unique_service_id = null
 
static $instances
 
static $settings
 
static $active_cache = array()
 

Detailed Description

Class ilGlobalCache.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 13 of file class.ilGlobalCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilGlobalCache::__construct (   $service_type)
protected
Parameters
$service_type

Definition at line 132 of file class.ilGlobalCache.php.

References $service_type, checkSettings(), generateServiceId(), and setServiceType().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkSettings()

ilGlobalCache::checkSettings ( )
protected

Definition at line 154 of file class.ilGlobalCache.php.

155 {
156 if (!$this->getSettings() instanceof ilGlobalCacheSettings) {
157 $ilGlobalCacheSettings = new ilGlobalCacheSettings();
158 $this->setSettings($ilGlobalCacheSettings);
159 }
160 }
Class ilGlobalCacheSettings.
static setSettings($settings)

References getSettings(), and setSettings().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilGlobalCache::delete (   $key)
Parameters
$key
Returns
bool

Definition at line 400 of file class.ilGlobalCache.php.

401 {
402 if (!$this->isActive()) {
403 return false;
404 }
405
406 return $this->global_cache->delete($key);
407 }

References isActive().

+ Here is the call graph for this function:

◆ exists()

ilGlobalCache::exists (   $key)
Parameters
$key
Returns
bool
Exceptions
RuntimeException

Definition at line 344 of file class.ilGlobalCache.php.

345 {
346 if (!$this->global_cache->isActive()) {
347 return false;
348 }
349
350 return $this->global_cache->exists($key);
351 }

◆ flush()

ilGlobalCache::flush (   $complete = false)
Parameters
bool$complete
Returns
bool
Exceptions
RuntimeException

Definition at line 414 of file class.ilGlobalCache.php.

415 {
416 if ($this->global_cache->isActive()) {
417 return $this->global_cache->flush($complete);
418 }
419
420 return false;
421 }

◆ generateServiceId()

static ilGlobalCache::generateServiceId ( )
staticprotected
Returns
string

Definition at line 182 of file class.ilGlobalCache.php.

183 {
184 if (!isset(self::$unique_service_id)) {
185 $rawServiceId = '_';
186 if (defined('CLIENT_ID')) {
187 $rawServiceId .= 'il_' . CLIENT_ID;
188 }
189 self::$unique_service_id = substr(md5($rawServiceId), 0, 6);
190 }
191 }
const CLIENT_ID
Definition: constants.php:39

References CLIENT_ID.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ get()

ilGlobalCache::get (   $key)
Parameters
$key
Returns
mixed
Exceptions
RuntimeException

Definition at line 376 of file class.ilGlobalCache.php.

377 {
378 if (!$this->isActive()) {
379 return false;
380 }
381 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
382 if ($unserialized_return) {
383 $service_name = ' [' . self::lookupServiceClassName($this->getServiceType()) . ']';
384 if ($this->global_cache->isValid($key)) {
385 self::log($key . ' from component ' . $this->getComponent() . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
386
387 return $unserialized_return;
388 } else {
389 self::log($key . ' from component ' . $this->getComponent() . ' is invalid' . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
390 }
391 }
392
393 return null;
394 }
static lookupServiceClassName($service_type)
static log($message, $log_level)

References getComponent(), getServiceType(), isActive(), log(), ilGlobalCacheSettings\LOG_LEVEL_CHATTY, and lookupServiceClassName().

+ Here is the call graph for this function:

◆ getActive()

ilGlobalCache::getActive ( )
Returns
boolean

Definition at line 455 of file class.ilGlobalCache.php.

456 {
457 return $this->active;
458 }

References $active.

Referenced by isActive().

+ Here is the caller graph for this function:

◆ getActiveComponents()

static ilGlobalCache::getActiveComponents ( )
static
Returns
array

Definition at line 502 of file class.ilGlobalCache.php.

503 {
505 }

References $active_components.

◆ getAllInstallableTypes()

static ilGlobalCache::getAllInstallableTypes ( )
static
Returns
ilGlobalCache[]

Definition at line 213 of file class.ilGlobalCache.php.

214 {
215 $types = array();
216 foreach (self::getAllTypes() as $type) {
217 if ($type->isCacheServiceInstallable()) {
218 $types[] = $type;
219 }
220 }
221
222 return $types;
223 }
$type

References $type, and $types.

◆ getAllTypes()

static ilGlobalCache::getAllTypes (   $only_available = true)
static
Parameters
bool$only_available
Returns
array

Definition at line 229 of file class.ilGlobalCache.php.

230 {
231 $types = array();
232 foreach (self::$types as $type) {
233 if ($only_available && !in_array($type, self::$available_types)) {
234 continue;
235 }
236 $obj = new self($type);
237 $obj->initCachingService();
238 $types[$type] = $obj;
239 }
240
241 return $types;
242 }

References $type, and $types.

◆ getAvailableComponents()

static ilGlobalCache::getAvailableComponents ( )
static

◆ getComponent()

ilGlobalCache::getComponent ( )
Returns
string

Definition at line 439 of file class.ilGlobalCache.php.

440 {
441 return $this->component;
442 }

References $component.

Referenced by get(), isActive(), and set().

+ Here is the caller graph for this function:

◆ getInfo()

ilGlobalCache::getInfo ( )

Definition at line 423 of file class.ilGlobalCache.php.

424 {
425 return $this->global_cache->getInfo();
426 }

◆ getInstallationFailureReason()

ilGlobalCache::getInstallationFailureReason ( )
Returns
string

Definition at line 334 of file class.ilGlobalCache.php.

335 {
336 return $this->global_cache->getInstallationFailureReason();
337 }

◆ getInstance()

static ilGlobalCache::getInstance (   $component)
static
Parameters
null$component
Returns
ilGlobalCache

Definition at line 115 of file class.ilGlobalCache.php.

116 {
117 if (!isset(self::$instances[$component])) {
118 $service_type = self::getSettings()->getService();
119 $ilGlobalCache = new self($service_type);
120 $ilGlobalCache->setComponent($component);
121 $ilGlobalCache->initCachingService();
122
123 self::$instances[$component] = $ilGlobalCache;
124 }
125
126 return self::$instances[$component];
127 }

References $component, $service_type, and getSettings().

Referenced by ilCachedComponentData\__construct(), ilMMItemRepository\__construct(), ilCachedCtrl\__construct(), arConnectorCache\__construct(), ilCachedComponentData\__destruct(), ilCachedComponentData\flush(), ilCachedCtrl\flush(), ilGlobalCacheQueryWrapper\get(), ilMMCustomItemStorage\getCache(), ilMMItemStorage\getCache(), ilMMItemTranslationStorage\getCache(), ilMMTypeActionStorage\getCache(), HTML_Template_IT\getFile(), ilCachedComponentData\getInstance(), ilCachedCtrl\getInstance(), HTML_Template_IT\init(), ilAppEventHandler\initListeners(), ilCachedCtrl\isActive(), and ilObjectDefinition\readDefinitionData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getServiceType()

ilGlobalCache::getServiceType ( )
Returns
int

Definition at line 474 of file class.ilGlobalCache.php.

475 {
476 if ($this->global_cache instanceof ilGlobalCacheService) {
477 return $this->global_cache->getServiceType();
478 }
479
480 return $this->service_type;
481 }
Class ilGlobalCacheService.

References $service_type.

Referenced by get().

+ Here is the caller graph for this function:

◆ getSettings()

static ilGlobalCache::getSettings ( )
static
Returns
ilGlobalCacheSettings

Definition at line 486 of file class.ilGlobalCache.php.

487 {
488 return (self::$settings instanceof ilGlobalCacheSettings ? self::$settings : new ilGlobalCacheSettings());
489 }

Referenced by checkSettings(), and getInstance().

+ Here is the caller graph for this function:

◆ isActive()

ilGlobalCache::isActive ( )
Returns
bool

Definition at line 280 of file class.ilGlobalCache.php.

281 {
282 $c = $this->getComponent();
283 if (isset(self::$active_cache[$c]) && self::$active_cache[$c] !== null) {
284 return self::$active_cache[$c];
285 }
286 if (!self::ACTIVE) {
287 self::$active_cache[$c] = false;
288
289 return false;
290 }
291 if (!$this->getActive()) {
292 self::log($c . '-wrapper is inactive...', ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
293 self::$active_cache[$c] = false;
294
295 return false;
296 }
297
298 $isActive = $this->global_cache->isActive();
299 self::log('component ' . $c . ', service is active: '
300 . ($isActive ? 'yes' : 'no'), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
301 self::$active_cache[$c] = $isActive;
302
303 return $isActive;
304 }
$c
Definition: cli.php:37

References $c, getActive(), getComponent(), log(), and ilGlobalCacheSettings\LOG_LEVEL_CHATTY.

Referenced by delete(), get(), and set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCacheServiceInstallable()

ilGlobalCache::isCacheServiceInstallable ( )
Returns
bool

Definition at line 326 of file class.ilGlobalCache.php.

327 {
328 return $this->global_cache->isInstallable();
329 }

◆ isInstallable()

ilGlobalCache::isInstallable ( )
Returns
bool

Definition at line 318 of file class.ilGlobalCache.php.

319 {
320 return count(self::getAllInstallableTypes()) > 0;
321 }

◆ isValid()

ilGlobalCache::isValid (   $key)
Parameters
$key
Returns
bool

Definition at line 310 of file class.ilGlobalCache.php.

311 {
312 return $this->global_cache->isValid($key);
313 }

◆ log()

static ilGlobalCache::log (   $message,
  $log_level 
)
static
Parameters
$message

Definition at line 165 of file class.ilGlobalCache.php.

166 {
167 if ($log_level <= self::getSettings()->getLogLevel()) {
168 global $DIC;
169 $ilLog = $DIC['ilLog'];
170 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
171 $function = $backtrace[1]['function'];
172 $class = $backtrace[1]['class'];
173 if ($ilLog instanceof ilComponentLogger) {
174 $ilLog->alert($class . '::' . $function . '(): ' . $message);
175 }
176 }
177 }
Component logger with individual log levels by component id.
global $DIC
Definition: goto.php:24
$message
Definition: xapiexit.php:14

References $DIC, and $message.

Referenced by get(), HTML_Template_IT\init(), isActive(), set(), and ilGlobalCacheSettings\writeToIniFile().

+ Here is the caller graph for this function:

◆ lookupServiceClassName()

static ilGlobalCache::lookupServiceClassName (   $service_type)
static

Definition at line 244 of file class.ilGlobalCache.php.

245 {
246 switch ($service_type) {
247 case self::TYPE_APC:
248 return ilApc::class;
250 return ilMemcache::class;
252 return ilXcache::class;
253 default:
254 return ilStaticCache::class;
255 }
256 }

References $service_type, TYPE_APC, TYPE_MEMCACHED, and TYPE_XCACHE.

Referenced by ilGlobalCacheSettings\__toString(), and get().

+ Here is the caller graph for this function:

◆ lookupServiceConfigName()

static ilGlobalCache::lookupServiceConfigName ( int  $service_type)
static

Definition at line 258 of file class.ilGlobalCache.php.

258 : string
259 {
260 switch ($service_type) {
261 case self::TYPE_APC:
262 return 'apc';
264 return 'memcached';
266 return 'xcache';
267 default:
268 return 'static';
269 }
270 }

References $service_type, TYPE_APC, TYPE_MEMCACHED, and TYPE_XCACHE.

Referenced by ilGlobalCacheMetricsCollectedObjective\collectFrom().

+ Here is the caller graph for this function:

◆ set()

ilGlobalCache::set (   $key,
  $value,
  $ttl = null 
)
Parameters
$key
$value
null$ttl
Returns
bool
Exceptions
RuntimeException

Definition at line 360 of file class.ilGlobalCache.php.

361 {
362 if (!$this->isActive()) {
363 return false;
364 }
365 self::log($key . ' set in component ' . $this->getComponent(), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
366 $this->global_cache->setValid($key);
367
368 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
369 }

References getComponent(), isActive(), log(), and ilGlobalCacheSettings\LOG_LEVEL_CHATTY.

+ Here is the call graph for this function:

◆ setActive()

ilGlobalCache::setActive (   $active)
Parameters
boolean$active

Definition at line 447 of file class.ilGlobalCache.php.

448 {
449 $this->active = $active;
450 }

References $active.

◆ setActiveComponents()

static ilGlobalCache::setActiveComponents (   $active_components)
static
Parameters
array$active_components

Definition at line 510 of file class.ilGlobalCache.php.

511 {
512 self::$active_components = $active_components;
513 }

References $active_components.

Referenced by setup().

+ Here is the caller graph for this function:

◆ setAvailableComponents()

static ilGlobalCache::setAvailableComponents (   $available_components)
static
Parameters
array$available_components

Definition at line 526 of file class.ilGlobalCache.php.

527 {
528 self::$available_components = $available_components;
529 }

References $available_components.

◆ setComponent()

ilGlobalCache::setComponent (   $component)
Parameters
string$component

Definition at line 431 of file class.ilGlobalCache.php.

432 {
433 $this->component = $component;
434 }

References $component.

◆ setServiceType()

ilGlobalCache::setServiceType (   $service_type)
Parameters
int$service_type

Definition at line 463 of file class.ilGlobalCache.php.

464 {
465 if ($this->global_cache instanceof ilGlobalCacheService) {
466 $this->global_cache->setServiceType($service_type);
467 }
468 $this->service_type = $service_type;
469 }

References $service_type.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setSettings()

static ilGlobalCache::setSettings (   $settings)
static
Parameters
ilGlobalCacheSettings$settings

Definition at line 494 of file class.ilGlobalCache.php.

495 {
496 self::$settings = $settings;
497 }

References $settings.

Referenced by checkSettings(), and setup().

+ Here is the caller graph for this function:

◆ setup()

static ilGlobalCache::setup ( ilGlobalCacheSettings  $ilGlobalCacheSettings)
static
Parameters
ilGlobalCacheSettings$ilGlobalCacheSettings

Definition at line 105 of file class.ilGlobalCache.php.

106 {
107 self::setSettings($ilGlobalCacheSettings);
108 self::setActiveComponents($ilGlobalCacheSettings->getActivatedComponents());
109 }
static setActiveComponents($active_components)

References ilGlobalCacheSettings\getActivatedComponents(), setActiveComponents(), and setSettings().

Referenced by ilInitialisation\initClientIniFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $active

ilGlobalCache::$active = true
protected

Definition at line 92 of file class.ilGlobalCache.php.

Referenced by getActive(), and setActive().

◆ $active_cache

ilGlobalCache::$active_cache = array()
staticprotected

Definition at line 275 of file class.ilGlobalCache.php.

◆ $active_components

ilGlobalCache::$active_components = array()
staticprotected

Definition at line 54 of file class.ilGlobalCache.php.

Referenced by getActiveComponents(), and setActiveComponents().

◆ $available_components

ilGlobalCache::$available_components
staticprotected
Initial value:
= array(
self::COMP_CLNG,
self::COMP_OBJ_DEF,
self::COMP_ILCTRL,
self::COMP_COMPONENT,
self::COMP_TEMPLATE,
self::COMP_TPL_BLOCKS,
self::COMP_TPL_VARIABLES,
self::COMP_EVENTS,
self::COMP_GLOBAL_SCREEN,
)

Definition at line 58 of file class.ilGlobalCache.php.

Referenced by getAvailableComponents(), and setAvailableComponents().

◆ $available_types

ilGlobalCache::$available_types
staticprotected
Initial value:
= array(
self::TYPE_MEMCACHED,
self::TYPE_XCACHE,
self::TYPE_APC,
self::TYPE_STATIC,
)

Definition at line 45 of file class.ilGlobalCache.php.

◆ $component

ilGlobalCache::$component
protected

Definition at line 88 of file class.ilGlobalCache.php.

Referenced by getComponent(), getInstance(), and setComponent().

◆ $global_cache

ilGlobalCache::$global_cache
protected

Definition at line 84 of file class.ilGlobalCache.php.

◆ $instances

ilGlobalCache::$instances
staticprotected

Definition at line 80 of file class.ilGlobalCache.php.

◆ $service_type

◆ $settings

ilGlobalCache::$settings
staticprotected

Definition at line 100 of file class.ilGlobalCache.php.

Referenced by setSettings().

◆ $type_per_component

ilGlobalCache::$type_per_component = array()
staticprotected

Definition at line 72 of file class.ilGlobalCache.php.

◆ $types

ilGlobalCache::$types
staticprotected
Initial value:
= array(
self::TYPE_MEMCACHED,
self::TYPE_XCACHE,
self::TYPE_APC,
self::TYPE_STATIC,
)

Definition at line 36 of file class.ilGlobalCache.php.

Referenced by getAllInstallableTypes(), and getAllTypes().

◆ $unique_service_id

ilGlobalCache::$unique_service_id = null
staticprotected

Definition at line 76 of file class.ilGlobalCache.php.

◆ ACTIVE

const ilGlobalCache::ACTIVE = true

Definition at line 16 of file class.ilGlobalCache.php.

◆ COMP_CLNG

const ilGlobalCache::COMP_CLNG = 'clng'

Definition at line 22 of file class.ilGlobalCache.php.

◆ COMP_COMPONENT

◆ COMP_EVENTS

const ilGlobalCache::COMP_EVENTS = 'events'

Definition at line 29 of file class.ilGlobalCache.php.

Referenced by ilAppEventHandler\initListeners().

◆ COMP_GLOBAL_SCREEN

◆ COMP_ILCTRL

const ilGlobalCache::COMP_ILCTRL = 'ilctrl'

◆ COMP_OBJ_DEF

const ilGlobalCache::COMP_OBJ_DEF = 'obj_def'

Definition at line 23 of file class.ilGlobalCache.php.

◆ COMP_PLUGINS

const ilGlobalCache::COMP_PLUGINS = 'plugins'

Definition at line 26 of file class.ilGlobalCache.php.

◆ COMP_RBAC_UA

const ilGlobalCache::COMP_RBAC_UA = 'rbac_ua'

Definition at line 28 of file class.ilGlobalCache.php.

◆ COMP_TEMPLATE

const ilGlobalCache::COMP_TEMPLATE = 'tpl'

Definition at line 24 of file class.ilGlobalCache.php.

Referenced by HTML_Template_IT\getFile().

◆ COMP_TPL_BLOCKS

const ilGlobalCache::COMP_TPL_BLOCKS = 'tpl_blocks'

Definition at line 30 of file class.ilGlobalCache.php.

Referenced by HTML_Template_IT\init().

◆ COMP_TPL_VARIABLES

const ilGlobalCache::COMP_TPL_VARIABLES = 'tpl_variables'

Definition at line 31 of file class.ilGlobalCache.php.

Referenced by HTML_Template_IT\init().

◆ MSG

const ilGlobalCache::MSG = 'Global Cache not active, can not access cache'

Definition at line 15 of file class.ilGlobalCache.php.

◆ TYPE_APC

const ilGlobalCache::TYPE_APC = 3

◆ TYPE_FALLBACK

const ilGlobalCache::TYPE_FALLBACK = self::TYPE_STATIC

Definition at line 21 of file class.ilGlobalCache.php.

◆ TYPE_MEMCACHED

◆ TYPE_STATIC

const ilGlobalCache::TYPE_STATIC = 0

◆ TYPE_XCACHE

const ilGlobalCache::TYPE_XCACHE = 1

The documentation for this class was generated from the following file: