ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 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'
 

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 14 of file class.ilGlobalCache.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 133 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 155 of file class.ilGlobalCache.php.

155 {
156 if (!$this->getSettings() instanceof ilGlobalCacheSettings) {
157
158 $ilGlobalCacheSettings = new ilGlobalCacheSettings();
159 $this->setSettings($ilGlobalCacheSettings);
160 }
161 }
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 398 of file class.ilGlobalCache.php.

398 {
399 if (!$this->isActive()) {
400 return false;
401 }
402
403 return $this->global_cache->delete($key);
404 }

References isActive().

+ Here is the call graph for this function:

◆ exists()

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

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

339 {
340 if (!$this->global_cache->isActive()) {
341 return false;
342 }
343
344 return $this->global_cache->exists($key);
345 }

◆ flush()

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

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

413 {
414 if ($this->global_cache->isActive()) {
415 if ($complete) {
416 return $this->global_cache->flush();
417 } else {
418 $this->global_cache->setInvalid();
419 }
420 }
421
422 return false;
423 }

◆ generateServiceId()

static ilGlobalCache::generateServiceId ( )
staticprotected
Returns
string

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

184 {
185 if (!isset(self::$unique_service_id)) {
186 self::$unique_service_id = substr(md5('il_' . CLIENT_ID), 0, 6);
187 }
188 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ get()

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

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

373 {
374 if (!$this->isActive()) {
375 return false;
376 }
377 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
378 if ($unserialized_return) {
379 $service_name = ' [' . self::lookupServiceClassName($this->getServiceType()) . ']';
380 if ($this->global_cache->isValid($key)) {
381 self::log($key . ' from component ' . $this->getComponent() . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
382
383 return $unserialized_return;
384 } else {
385 self::log($key . ' from component ' . $this->getComponent() . ' is invalid' . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
386 }
387 }
388
389 return null;
390 }
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 458 of file class.ilGlobalCache.php.

458 {
459 return $this->active;
460 }

References $active.

Referenced by isActive().

+ Here is the caller graph for this function:

◆ getActiveComponents()

static ilGlobalCache::getActiveComponents ( )
static
Returns
array

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

505 {
507 }

References $active_components.

◆ getAllInstallableTypes()

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

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

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

References $types.

◆ getAllTypes()

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

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

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

References $types.

◆ getAvailableComponents()

static ilGlobalCache::getAvailableComponents ( )
static
Returns
array

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

521 {
523 }

References $available_components.

Referenced by ilGlobalCacheSettings\activateAll(), ilGlobalCacheSettings\areAllComponentActivated(), and ilGlobalCacheSettings\writeToIniFile().

+ Here is the caller graph for this function:

◆ getComponent()

ilGlobalCache::getComponent ( )
Returns
string

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

442 {
443 return $this->component;
444 }

References $component.

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

+ Here is the caller graph for this function:

◆ getInfo()

ilGlobalCache::getInfo ( )

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

426 {
427 return $this->global_cache->getInfo();
428 }

◆ getInstallationFailureReason()

ilGlobalCache::getInstallationFailureReason ( )
Returns
string

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

328 {
329 return $this->global_cache->getInstallationFailureReason();
330 }

◆ getInstance()

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

Definition at line 116 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(), ilCachedCtrl\__construct(), ilCachedComponentData\__destruct(), ilCachedComponentData\flush(), ilCachedCtrl\flush(), ilGlobalCacheQueryWrapper\get(), 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 477 of file class.ilGlobalCache.php.

477 {
478 if ($this->global_cache instanceof ilGlobalCacheService) {
479 return $this->global_cache->getServiceType();
480 }
481
482 return $this->service_type;
483 }
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 489 of file class.ilGlobalCache.php.

489 {
490 return (self::$settings instanceof ilGlobalCacheSettings ? self::$settings : new ilGlobalCacheSettings());
491 }

Referenced by checkSettings(), and getInstance().

+ Here is the caller graph for this function:

◆ isActive()

ilGlobalCache::isActive ( )
Returns
bool

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

274 {
275 if (self::$active_cache[$this->getComponent()] !== null) {
276 return self::$active_cache[$this->getComponent()];
277 }
278 if (!self::ACTIVE) {
279 self::$active_cache[$this->getComponent()] = false;
280
281 return false;
282 }
283 if (!$this->getActive()) {
284 self::log($this->getComponent() . '-wrapper is inactive...', ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
285 self::$active_cache[$this->getComponent()] = false;
286
287 return false;
288 }
289
290 $isActive = $this->global_cache->isActive();
291 self::log('component ' . $this->getComponent() . ', service is active: '
292 . ($isActive ? 'yes' : 'no'), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
293 self::$active_cache[$this->getComponent()] = $isActive;
294
295 return $isActive;
296 }

References 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 320 of file class.ilGlobalCache.php.

320 {
321 return $this->global_cache->isInstallable();
322 }

◆ isInstallable()

ilGlobalCache::isInstallable ( )
Returns
bool

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

312 {
313 return count(self::getAllInstallableTypes()) > 0;
314 }

◆ isValid()

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

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

304 {
305 return $this->global_cache->isValid($key);
306 }

◆ log()

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

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

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

References $DIC, and $ilLog.

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
Parameters
$service_type
Returns
string

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

247 {
248 switch ($service_type) {
249 case self::TYPE_APC:
250 return 'ilApc';
251 break;
253 return 'ilMemcache';
254 break;
256 return 'ilXcache';
257 break;
258 default:
259 return 'ilStaticCache';
260 break;
261 }
262 }

References $service_type, TYPE_APC, TYPE_MEMCACHED, and TYPE_XCACHE.

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

+ Here is the caller graph for this function:

◆ set()

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

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

356 {
357 if (!$this->isActive()) {
358 return false;
359 }
360 self::log($key . ' set in component ' . $this->getComponent(), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
361 $this->global_cache->setValid($key);
362
363 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
364 }

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 450 of file class.ilGlobalCache.php.

450 {
451 $this->active = $active;
452 }

References $active.

◆ setActiveComponents()

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

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

513 {
514 self::$active_components = $active_components;
515 }

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 529 of file class.ilGlobalCache.php.

529 {
530 self::$available_components = $available_components;
531 }

References $available_components.

◆ setComponent()

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

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

434 {
435 $this->component = $component;
436 }

References $component.

◆ setServiceType()

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

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

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

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 497 of file class.ilGlobalCache.php.

497 {
498 self::$settings = $settings;
499 }

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.

105 {
106 self::setSettings($ilGlobalCacheSettings);
107 self::setActiveComponents($ilGlobalCacheSettings->getActivatedComponents());
108 }
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 91 of file class.ilGlobalCache.php.

Referenced by getActive(), and setActive().

◆ $active_cache

ilGlobalCache::$active_cache = array()
staticprotected

Definition at line 268 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,
)

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 87 of file class.ilGlobalCache.php.

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

◆ $global_cache

ilGlobalCache::$global_cache
protected

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

◆ $instances

ilGlobalCache::$instances
staticprotected

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

◆ $service_type

ilGlobalCache::$service_type = ilGlobalCache::TYPE_STATIC
protected

◆ $settings

ilGlobalCache::$settings
staticprotected

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

Referenced by setSettings().

◆ $type_per_component

ilGlobalCache::$type_per_component = array()
staticprotected

Definition at line 71 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 75 of file class.ilGlobalCache.php.

◆ ACTIVE

const ilGlobalCache::ACTIVE = true

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

◆ COMP_CLNG

const ilGlobalCache::COMP_CLNG = 'clng'

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

◆ COMP_COMPONENT

◆ COMP_EVENTS

const ilGlobalCache::COMP_EVENTS = 'events'

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

Referenced by ilAppEventHandler\initListeners().

◆ COMP_ILCTRL

const ilGlobalCache::COMP_ILCTRL = 'ilctrl'

◆ COMP_OBJ_DEF

const ilGlobalCache::COMP_OBJ_DEF = 'obj_def'

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

◆ COMP_PLUGINS

const ilGlobalCache::COMP_PLUGINS = 'plugins'

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

◆ COMP_RBAC_UA

const ilGlobalCache::COMP_RBAC_UA = 'rbac_ua'

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

◆ COMP_TEMPLATE

const ilGlobalCache::COMP_TEMPLATE = 'tpl'

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

Referenced by HTML_Template_IT\getFile().

◆ COMP_TPL_BLOCKS

const ilGlobalCache::COMP_TPL_BLOCKS = 'tpl_blocks'

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

Referenced by HTML_Template_IT\init().

◆ COMP_TPL_VARIABLES

const ilGlobalCache::COMP_TPL_VARIABLES = 'tpl_variables'

Definition at line 32 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 16 of file class.ilGlobalCache.php.

◆ TYPE_APC

const ilGlobalCache::TYPE_APC = 3

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

Referenced by lookupServiceClassName().

◆ TYPE_FALLBACK

const ilGlobalCache::TYPE_FALLBACK = self::TYPE_STATIC

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

◆ TYPE_MEMCACHED

const ilGlobalCache::TYPE_MEMCACHED = 2

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

Referenced by lookupServiceClassName().

◆ TYPE_STATIC

const ilGlobalCache::TYPE_STATIC = 0

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

◆ TYPE_XCACHE

const ilGlobalCache::TYPE_XCACHE = 1

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

Referenced by lookupServiceClassName().


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