ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ()
 
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 $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 124 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 146 of file class.ilGlobalCache.php.

146 {
147 if (! $this->getSettings() instanceof ilGlobalCacheSettings) {
148
149 $ilGlobalCacheSettings = new ilGlobalCacheSettings();
150 $this->setSettings($ilGlobalCacheSettings);
151 }
152 }
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 384 of file class.ilGlobalCache.php.

384 {
385 if (! $this->isActive()) {
386 return false;
387 }
388
389 return $this->global_cache->delete($key);
390 }

References isActive().

+ Here is the call graph for this function:

◆ exists()

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

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

325 {
326 if (! $this->global_cache->isActive()) {
327 return false;
328 }
329
330 return $this->global_cache->exists($key);
331 }

◆ flush()

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

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

399 {
400 if ($this->global_cache->isActive()) {
401 if ($complete) {
402 return $this->global_cache->flush();
403 } else {
404 $this->global_cache->setInvalid();
405 }
406 }
407
408 return false;
409 }

◆ generateServiceId()

static ilGlobalCache::generateServiceId ( )
staticprotected
Returns
string

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

174 {
175 if (! isset(self::$unique_service_id)) {
176 self::$unique_service_id = substr(md5('il_' . CLIENT_ID), 0, 6);
177 }
178 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ get()

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

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

359 {
360 if (! $this->isActive()) {
361 return false;
362 }
363 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
364 if ($unserialized_return) {
365 $service_name = ' [' . self::lookupServiceClassName($this->getServiceType()) . ']';
366 if ($this->global_cache->isValid($key)) {
367 self::log($key . ' from component ' . $this->getComponent() . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
368
369 return $unserialized_return;
370 } else {
371 self::log($key . ' from component ' . $this->getComponent() . ' is invalid' . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
372 }
373 }
374
375 return NULL;
376 }
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 444 of file class.ilGlobalCache.php.

444 {
445 return $this->active;
446 }

References $active.

Referenced by isActive().

+ Here is the caller graph for this function:

◆ getActiveComponents()

static ilGlobalCache::getActiveComponents ( )
static
Returns
array

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

491 {
493 }

References $active_components.

◆ getAllInstallableTypes()

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

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

201 {
202 $types = array();
203 foreach (self::getAllTypes() as $type) {
204 if ($type->isCacheServiceInstallable()) {
205 $types[] = $type;
206 }
207 }
208
209 return $types;
210 }

References $types.

◆ getAllTypes()

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

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

216 {
217 $types = array();
218 foreach (self::$types as $type) {
219 $obj = new self($type);
220 $obj->initCachingService();
221 $types[$type] = $obj;
222 }
223
224 return $types;
225 }

References $types.

◆ getAvailableComponents()

static ilGlobalCache::getAvailableComponents ( )
static
Returns
array

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

507 {
509 }

References $available_components.

Referenced by ilGlobalCacheSettings\writeToIniFile().

+ Here is the caller graph for this function:

◆ getComponent()

ilGlobalCache::getComponent ( )
Returns
string

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

428 {
429 return $this->component;
430 }

References $component.

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

+ Here is the caller graph for this function:

◆ getInfo()

ilGlobalCache::getInfo ( )

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

412 {
413 return $this->global_cache->getInfo();
414 }

◆ getInstallationFailureReason()

ilGlobalCache::getInstallationFailureReason ( )
Returns
string

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

314 {
315 return $this->global_cache->getInstallationFailureReason();
316 }

◆ getInstance()

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

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

107 {
108 if (! isset(self::$instances[$component])) {
109 $service_type = self::getSettings()->getService();
110 $ilGlobalCache = new self($service_type);
111 $ilGlobalCache->setComponent($component);
112 $ilGlobalCache->initCachingService();
113
114 self::$instances[$component] = $ilGlobalCache;
115 }
116
117 return self::$instances[$component];
118 }

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

Referenced by ilGlobalCacheDBLayer\__construct(), 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 463 of file class.ilGlobalCache.php.

463 {
464 if ($this->global_cache instanceof ilGlobalCacheService) {
465 return $this->global_cache->getServiceType();
466 }
467
468 return $this->service_type;
469 }
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 475 of file class.ilGlobalCache.php.

475 {
476 return (self::$settings instanceof ilGlobalCacheSettings ? self::$settings : new ilGlobalCacheSettings());
477 }

Referenced by checkSettings(), and getInstance().

+ Here is the caller graph for this function:

◆ isActive()

ilGlobalCache::isActive ( )
Returns
bool

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

260 {
261 if (self::$active_cache[$this->getComponent()] !== NULL) {
262 return self::$active_cache[$this->getComponent()];
263 }
264 if (! self::ACTIVE) {
265 self::$active_cache[$this->getComponent()] = false;
266
267 return false;
268 }
269 if (! $this->getActive()) {
270 self::log($this->getComponent() . '-wrapper is inactive...', ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
271 self::$active_cache[$this->getComponent()] = false;
272
273 return false;
274 }
275
276 $isActive = $this->global_cache->isActive();
277 self::log('component ' . $this->getComponent() . ', service is active: '
278 . ($isActive ? 'yes' : 'no'), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
279 self::$active_cache[$this->getComponent()] = $isActive;
280
281 return $isActive;
282 }

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

306 {
307 return $this->global_cache->isInstallable();
308 }

◆ isInstallable()

ilGlobalCache::isInstallable ( )
Returns
bool

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

298 {
299 return count(self::getAllInstallableTypes()) > 0;
300 }

◆ isValid()

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

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

290 {
291 return $this->global_cache->isValid($key);
292 }

◆ log()

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

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

158 {
159 if ($log_level <= self::getSettings()->getLogLevel()) {
160 global $ilLog;
161 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
162 $function = $backtrace[1]['function'];
163 $class = $backtrace[1]['class'];
164 if ($ilLog instanceof ilLog) {
165 $ilLog->write($class . '::' . $function . '(): ' . $message);
166 }
167 }
168 }
logging
Definition: class.ilLog.php:19

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

233 {
234 switch ($service_type) {
235 case self::TYPE_APC:
236 return 'ilApc';
237 break;
239 return 'ilMemcache';
240 break;
242 return 'ilXcache';
243 break;
244 default:
245 return 'ilStaticCache';
246 break;
247 }
248 }

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

342 {
343 if (! $this->isActive()) {
344 return false;
345 }
346 self::log($key . ' set in component ' . $this->getComponent(), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
347 $this->global_cache->setValid($key);
348
349 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
350 }

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

436 {
437 $this->active = $active;
438 }

References $active.

◆ setActiveComponents()

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

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

499 {
500 self::$active_components = $active_components;
501 }

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

515 {
516 self::$available_components = $available_components;
517 }

References $available_components.

◆ setComponent()

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

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

420 {
421 $this->component = $component;
422 }

References $component.

◆ setServiceType()

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

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

452 {
453 if ($this->global_cache instanceof ilGlobalCacheService) {
454 $this->global_cache->setServiceType($service_type);
455 }
456 $this->service_type = $service_type;
457 }

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

483 {
484 self::$settings = $settings;
485 }

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

96 {
97 self::setSettings($ilGlobalCacheSettings);
98 self::setActiveComponents($ilGlobalCacheSettings->getActivatedComponents());
99 }
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 82 of file class.ilGlobalCache.php.

Referenced by getActive(), and setActive().

◆ $active_cache

ilGlobalCache::$active_cache = array()
staticprotected

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

◆ $active_components

ilGlobalCache::$active_components = array()
staticprotected

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

Referenced by getAvailableComponents(), and setAvailableComponents().

◆ $component

ilGlobalCache::$component
protected

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

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

◆ $global_cache

ilGlobalCache::$global_cache
protected

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

◆ $instances

ilGlobalCache::$instances
staticprotected

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

◆ $service_type

ilGlobalCache::$service_type = ilGlobalCache::TYPE_STATIC
protected

◆ $settings

ilGlobalCache::$settings
staticprotected

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

Referenced by setSettings().

◆ $type_per_component

ilGlobalCache::$type_per_component = array()
staticprotected

Definition at line 62 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 66 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: