ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 135 of file class.ilGlobalCache.php.

References $service_type, checkSettings(), getComponent(), getServiceType(), setActive(), setComponent(), and setServiceType().

136  {
137  $this->checkSettings();
138  self::generateServiceId();
140  }
setServiceType($service_type)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkSettings()

ilGlobalCache::checkSettings ( )
protected

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

References getSettings(), and setSettings().

Referenced by __construct().

160  {
161  if (!$this->getSettings() instanceof ilGlobalCacheSettings) {
162  $ilGlobalCacheSettings = new ilGlobalCacheSettings();
163  $this->setSettings($ilGlobalCacheSettings);
164  }
165  }
Class ilGlobalCacheSettings.
static setSettings($settings)
+ 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 420 of file class.ilGlobalCache.php.

References $key, and isActive().

421  {
422  if (!$this->isActive()) {
423  return false;
424  }
425 
426  return $this->global_cache->delete($key);
427  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ exists()

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

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

References $key.

359  {
360  if (!$this->global_cache->isActive()) {
361  return false;
362  }
363 
364  return $this->global_cache->exists($key);
365  }
$key
Definition: croninfo.php:18

◆ flush()

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

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

437  {
438  if ($this->global_cache->isActive()) {
439  return $this->global_cache->flush();
440  }
441 
442  return false;
443  }

◆ generateServiceId()

static ilGlobalCache::generateServiceId ( )
staticprotected
Returns
string

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

References $service, $type, defined, and ilGlobalCacheSettings\LOG_LEVEL_NORMAL.

190  {
191  if (!isset(self::$unique_service_id)) {
192  $rawServiceId = '_';
193  if (defined('CLIENT_ID')) {
194  $rawServiceId .= 'il_' . CLIENT_ID;
195  }
196  self::$unique_service_id = substr(md5($rawServiceId), 0, 6);
197  }
198  }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

◆ get()

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

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

References $key, getComponent(), getServiceType(), isActive(), and ilGlobalCacheSettings\LOG_LEVEL_CHATTY.

395  {
396  if (!$this->isActive()) {
397  return false;
398  }
399  $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
400  if ($unserialized_return) {
401  $service_name = ' [' . self::lookupServiceClassName($this->getServiceType()) . ']';
402  if ($this->global_cache->isValid($key)) {
403  self::log($key . ' from component ' . $this->getComponent() . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
404 
405  return $unserialized_return;
406  } else {
407  self::log($key . ' from component ' . $this->getComponent() . ' is invalid' . $service_name, ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
408  }
409  }
410 
411  return null;
412  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getActive()

ilGlobalCache::getActive ( )
Returns
boolean

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

References $active.

Referenced by isActive().

483  {
484  return $this->active;
485  }
+ Here is the caller graph for this function:

◆ getActiveComponents()

static ilGlobalCache::getActiveComponents ( )
static
Returns
array

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

535  {
536  return self::$active_components;
537  }

◆ getAllInstallableTypes()

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

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

References $type, $types, and array.

223  {
224  $types = array();
225  foreach (self::getAllTypes() as $type) {
226  if ($type->isCacheServiceInstallable()) {
227  $types[] = $type;
228  }
229  }
230 
231  return $types;
232  }
$type
Create styles array
The data for the language used.

◆ getAllTypes()

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

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

References $type, $types, and array.

Referenced by ilSetupGUI\bt_tabs().

240  {
241  $types = array();
242  foreach (self::$types as $type) {
243  if ($only_available && !in_array($type, self::$available_types)) {
244  continue;
245  }
246  $obj = new self($type);
247  $obj->initCachingService();
248  $types[$type] = $obj;
249  }
250 
251  return $types;
252  }
$type
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getAvailableComponents()

static ilGlobalCache::getAvailableComponents ( )
static
Returns
array

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

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

553  {
554  return self::$available_components;
555  }
+ Here is the caller graph for this function:

◆ getComponent()

ilGlobalCache::getComponent ( )
Returns
string

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

References $component.

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

465  {
466  return $this->component;
467  }
+ Here is the caller graph for this function:

◆ getInfo()

ilGlobalCache::getInfo ( )

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

447  {
448  return $this->global_cache->getInfo();
449  }

◆ getInstallationFailureReason()

ilGlobalCache::getInstallationFailureReason ( )
Returns
string

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

347  {
348  return $this->global_cache->getInstallationFailureReason();
349  }

◆ getInstance()

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

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

References $component, and $service_type.

Referenced by ilCachedCtrl\__construct(), ilCachedComponentData\__construct(), ilCachedComponentData\__destruct(), ilCachedCtrl\flush(), ilCachedComponentData\flush(), ilGlobalCacheQueryWrapper\get(), HTML_Template_IT\getFile(), ilCachedCtrl\getInstance(), ilCachedComponentData\getInstance(), HTML_Template_IT\init(), ilAppEventHandler\initListeners(), ilCachedCtrl\isActive(), and ilObjectDefinition\readDefinitionData().

118  {
119  if (!isset(self::$instances[$component])) {
120  $service_type = self::getSettings()->getService();
121  $ilGlobalCache = new self($service_type);
122  $ilGlobalCache->setComponent($component);
123  $ilGlobalCache->initCachingService();
124 
125  self::$instances[$component] = $ilGlobalCache;
126  }
127 
128  return self::$instances[$component];
129  }
+ Here is the caller graph for this function:

◆ getServiceType()

ilGlobalCache::getServiceType ( )
Returns
int

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

References $service_type.

Referenced by __construct(), and get().

504  {
505  if ($this->global_cache instanceof ilGlobalCacheService) {
506  return $this->global_cache->getServiceType();
507  }
508 
509  return $this->service_type;
510  }
Class ilGlobalCacheService.
+ Here is the caller graph for this function:

◆ getSettings()

static ilGlobalCache::getSettings ( )
static
Returns
ilGlobalCacheSettings

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

Referenced by checkSettings().

517  {
518  return (self::$settings instanceof ilGlobalCacheSettings ? self::$settings : new ilGlobalCacheSettings());
519  }
Class ilGlobalCacheSettings.
+ Here is the caller graph for this function:

◆ isActive()

ilGlobalCache::isActive ( )
Returns
bool

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

References getActive(), getComponent(), and ilGlobalCacheSettings\LOG_LEVEL_CHATTY.

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

289  {
290  if (self::$active_cache[$this->getComponent()] !== null) {
291  return self::$active_cache[$this->getComponent()];
292  }
293  if (!self::ACTIVE) {
294  self::$active_cache[$this->getComponent()] = false;
295 
296  return false;
297  }
298  if (!$this->getActive()) {
299  self::log($this->getComponent() . '-wrapper is inactive...', ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
300  self::$active_cache[$this->getComponent()] = false;
301 
302  return false;
303  }
304 
305  $isActive = $this->global_cache->isActive();
306  self::log('component ' . $this->getComponent() . ', service is active: '
307  . ($isActive ? 'yes' : 'no'), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
308  self::$active_cache[$this->getComponent()] = $isActive;
309 
310  return $isActive;
311  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCacheServiceInstallable()

ilGlobalCache::isCacheServiceInstallable ( )
Returns
bool

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

338  {
339  return $this->global_cache->isInstallable();
340  }

◆ isInstallable()

ilGlobalCache::isInstallable ( )
Returns
bool

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

329  {
330  return count(self::getAllInstallableTypes()) > 0;
331  }

◆ isValid()

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

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

References $key.

320  {
321  return $this->global_cache->isValid($key);
322  }
$key
Definition: croninfo.php:18

◆ log()

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

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

References $DIC, $function, $ilLog, and $message.

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

172  {
173  if ($log_level <= self::getSettings()->getLogLevel()) {
174  global $DIC;
175  $ilLog = $DIC['ilLog'];
176  $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
177  $function = $backtrace[1]['function'];
178  $class = $backtrace[1]['class'];
179  if ($ilLog instanceof ilComponentLogger) {
180  $ilLog->alert($class . '::' . $function . '(): ' . $message);
181  }
182  }
183  }
global $DIC
Definition: saml.php:7
Component logger with individual log levels by component id.
catch(Exception $e) $message
$function
Definition: cas.php:28
+ Here is the caller graph for this function:

◆ lookupServiceClassName()

static ilGlobalCache::lookupServiceClassName (   $service_type)
static
Parameters
$service_type
Returns
string

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

References $service_type.

Referenced by ilGlobalCacheSettings\__toString().

261  {
262  switch ($service_type) {
263  case self::TYPE_APC:
264  return 'ilApc';
265  break;
266  case self::TYPE_MEMCACHED:
267  return 'ilMemcache';
268  break;
269  case self::TYPE_XCACHE:
270  return 'ilXcache';
271  break;
272  default:
273  return 'ilStaticCache';
274  break;
275  }
276  }
+ 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 376 of file class.ilGlobalCache.php.

References $key, getComponent(), isActive(), and ilGlobalCacheSettings\LOG_LEVEL_CHATTY.

377  {
378  if (!$this->isActive()) {
379  return false;
380  }
381  self::log($key . ' set in component ' . $this->getComponent(), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
382  $this->global_cache->setValid($key);
383 
384  return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
385  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ setActive()

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

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

References $active.

Referenced by __construct().

474  {
475  $this->active = $active;
476  }
+ Here is the caller graph for this function:

◆ setActiveComponents()

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

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

References $active_components.

544  {
545  self::$active_components = $active_components;
546  }

◆ setAvailableComponents()

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

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

References $available_components.

562  {
563  self::$available_components = $available_components;
564  }

◆ setComponent()

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

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

References $component.

Referenced by __construct().

456  {
457  $this->component = $component;
458  }
+ Here is the caller graph for this function:

◆ setServiceType()

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

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

References $service_type.

Referenced by __construct().

492  {
493  if ($this->global_cache instanceof ilGlobalCacheService) {
494  $this->global_cache->setServiceType($service_type);
495  }
496  $this->service_type = $service_type;
497  }
Class ilGlobalCacheService.
+ Here is the caller graph for this function:

◆ setSettings()

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

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

References $settings.

Referenced by checkSettings().

526  {
527  self::$settings = $settings;
528  }
+ 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.

References ilGlobalCacheSettings\getActivatedComponents().

Referenced by ilInitialisation\initClientIniFile().

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

◆ $active_components

ilGlobalCache::$active_components = array()
staticprotected

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

Referenced by setActiveComponents().

◆ $available_components

ilGlobalCache::$available_components
staticprotected
Initial value:
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 setAvailableComponents().

◆ $available_types

ilGlobalCache::$available_types
staticprotected
Initial value:
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:
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.

◆ 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 ilSetupGUI\bt_tabs().

◆ 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.


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