ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilGlobalCache Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilGlobalCache:

Public Member Functions

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

Static Public Member Functions

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

Data Fields

const MSG = 'Global Cache not active, can not access cache'
 
const ACTIVE = true
 
const TYPE_STATIC = 0
 
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_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 (int $service_type)
 
 checkSettings ()
 

Static Protected Member Functions

static generateServiceId ()
 

Protected Attributes

ilGlobalCacheService $global_cache
 
string $component = null
 
bool $active = true
 
int $service_type = ilGlobalCache::TYPE_STATIC
 

Static Protected Attributes

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

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 24 of file class.ilGlobalCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilGlobalCache::__construct ( int  $service_type)
protected

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

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

141  {
142  self::generateServiceId();
144  }
setServiceType(int $service_type)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkSettings()

ilGlobalCache::checkSettings ( )
protected

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

162  : void
163  {
164  }

◆ delete()

ilGlobalCache::delete ( string  $key)

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

References isActive().

368  : bool
369  {
370  if (!$this->isActive()) {
371  return false;
372  }
373 
374  return $this->global_cache->delete($key);
375  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ exists()

ilGlobalCache::exists ( string  $key)
Exceptions
RuntimeException

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

314  : bool
315  {
316  if (!$this->global_cache->isActive()) {
317  return false;
318  }
319 
320  return $this->global_cache->exists($key);
321  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ flush()

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

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

380  : bool
381  {
382  if ($this->global_cache->isActive()) {
383  return $this->global_cache->flush($complete);
384  }
385 
386  return false;
387  }

◆ generateServiceId()

static ilGlobalCache::generateServiceId ( )
staticprotected

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

References $service, $serviceName, $type, CLIENT_ID, and ilGlobalCacheSettings\LOG_LEVEL_NORMAL.

180  : string
181  {
182  if (!isset(self::$unique_service_id)) {
183  $raw_service_id = '_';
184  if (defined('CLIENT_ID')) {
185  $raw_service_id .= 'il_' . CLIENT_ID;
186  }
187  self::$unique_service_id = substr(md5($raw_service_id), 0, 6);
188  }
189  return self::$unique_service_id;
190  }
const CLIENT_ID
Definition: constants.php:41

◆ get()

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

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

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

Referenced by ilCachedObjectDefinition\getInstance().

343  {
344  if (!$this->isActive()) {
345  return false;
346  }
347  $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
348  if ($unserialized_return) {
349  $service_name = ' [' . self::lookupServiceClassName($this->getServiceType()) . ']';
350  if ($this->global_cache->isValid($key)) {
351  self::log(
352  $key . ' from component ' . $this->getComponent() . $service_name,
354  );
355 
356  return $unserialized_return;
357  } else {
358  self::log(
359  $key . ' from component ' . $this->getComponent() . ' is invalid' . $service_name,
361  );
362  }
363  }
364 
365  return null;
366  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActive()

ilGlobalCache::getActive ( )

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

References $active.

Referenced by isActive().

409  : bool
410  {
411  return $this->active;
412  }
+ Here is the caller graph for this function:

◆ getActiveComponents()

static ilGlobalCache::getActiveComponents ( )
static

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

434  : array
435  {
436  return self::$active_components;
437  }

◆ getAllInstallableTypes()

static ilGlobalCache::getAllInstallableTypes ( )
static

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

References $type, and $types.

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

◆ getAllTypes()

static ilGlobalCache::getAllTypes ( bool  $only_available = true)
static

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

References $type, and $types.

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

◆ getAvailableComponents()

static ilGlobalCache::getAvailableComponents ( )
static

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

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

444  : array
445  {
446  return self::$available_components;
447  }
+ Here is the caller graph for this function:

◆ getComponent()

ilGlobalCache::getComponent ( )

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

References $component.

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

399  : ?string
400  {
401  return $this->component;
402  }
+ Here is the caller graph for this function:

◆ getInfo()

ilGlobalCache::getInfo ( )

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

389  : array
390  {
391  return $this->global_cache->getInfo();
392  }

◆ getInstallationFailureReason()

ilGlobalCache::getInstallationFailureReason ( )

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

306  : string
307  {
308  return $this->global_cache->getInstallationFailureReason();
309  }

◆ getInstance()

static ilGlobalCache::getInstance ( ?string  $component)
static

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

References $component, $service_type, and ILIAS\LTI\ToolProvider\getSettings().

Referenced by arConnectorCache\__construct(), ilCachedObjectDefinition\__construct(), ilCachedLanguage\__construct(), ilMMItemRepository\__construct(), ilCachedObjectDefinition\__destruct(), ilCachedObjectDefinition\flush(), ilMMItemStorage\getCache(), ilMMTypeActionStorage\getCache(), ilMMItemTranslationStorage\getCache(), ilMMCustomItemStorage\getCache(), HTML_Template_IT\getFile(), ilCachedObjectDefinition\getInstance(), HTML_Template_IT\init(), ilAppEventHandler\initListeners(), ilObjectDefinition\readDefinitionData(), ilServicesGlobalCacheTest\testService(), and ilServicesGlobalCacheTest\testValues().

127  {
128  if (!isset(self::$instances[$component])) {
129  $service_type = self::getSettings()->getService();
130  $ilGlobalCache = new self($service_type);
131  $ilGlobalCache->setComponent($component);
132  $ilGlobalCache->initCachingService();
133 
134  self::$instances[$component] = $ilGlobalCache;
135  }
136 
137  return self::$instances[$component];
138  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSettings()
Get an array of all setting values.
Definition: System.php:287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getServiceType()

ilGlobalCache::getServiceType ( )

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

References $service_type.

Referenced by __construct(), and get().

419  : int
420  {
421  return $this->service_type;
422  }
+ Here is the caller graph for this function:

◆ getSettings()

static ilGlobalCache::getSettings ( )
static

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

References ILIAS\LTI\ToolProvider\$settings.

425  {
427  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ilGlobalCacheSettings.

◆ isActive()

ilGlobalCache::isActive ( )

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

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

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

265  : bool
266  {
267  $c = $this->getComponent();
268  if (isset(self::$active_cache[$c]) && self::$active_cache[$c] !== null) {
269  return self::$active_cache[$c];
270  }
271  if (!self::ACTIVE) {
272  self::$active_cache[$c] = false;
273 
274  return false;
275  }
276  if (!$this->getActive()) {
277  self::log($c . '-wrapper is inactive...', ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
278  self::$active_cache[$c] = false;
279 
280  return false;
281  }
282 
283  $isActive = $this->global_cache->isActive();
284  self::log('component ' . $c . ', service is active: '
285  . ($isActive ? 'yes' : 'no'), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
286  self::$active_cache[$c] = $isActive;
287 
288  return $isActive;
289  }
$c
Definition: cli.php:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCacheServiceInstallable()

ilGlobalCache::isCacheServiceInstallable ( )

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

301  : bool
302  {
303  return $this->global_cache->isInstallable();
304  }

◆ isInstallable()

ilGlobalCache::isInstallable ( )

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

296  : bool
297  {
298  return count(self::getAllInstallableTypes()) > 0;
299  }

◆ isValid()

ilGlobalCache::isValid ( string  $key)

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

291  : bool
292  {
293  return $this->global_cache->isValid($key);
294  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ log()

static ilGlobalCache::log ( string  $message,
int  $log_level 
)
static

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

References $DIC, and ILIAS\LTI\ToolProvider\getSettings().

Referenced by HTML_Template_IT\init().

166  : void
167  {
168  if ($log_level <= self::getSettings()->getLogLevel()) {
169  global $DIC;
170  $ilLog = $DIC[\ilLog::class];
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
Definition: feed.php:28
getSettings()
Get an array of all setting values.
Definition: System.php:287
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupServiceClassName()

static ilGlobalCache::lookupServiceClassName ( int  $service_type)
static

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

Referenced by ilGlobalCacheSettings\__toString().

239  : string
240  {
241  switch ($service_type) {
242  case self::TYPE_APC:
243  return ilApc::class;
244  case self::TYPE_MEMCACHED:
245  return ilMemcache::class;
246  default:
247  return ilStaticCache::class;
248  }
249  }
+ Here is the caller graph for this function:

◆ lookupServiceConfigName()

static ilGlobalCache::lookupServiceConfigName ( int  $service_type)
static

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

Referenced by ilGlobalCacheMetricsCollectedObjective\collectFrom().

251  : string
252  {
253  switch ($service_type) {
254  case self::TYPE_APC:
255  return 'apc';
256  case self::TYPE_MEMCACHED:
257  return 'memcached';
258  default:
259  return 'static';
260  }
261  }
+ Here is the caller graph for this function:

◆ set()

ilGlobalCache::set ( string  $key,
  $value,
int  $ttl = null 
)
Parameters
mixed$value
Exceptions
RuntimeException

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

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

Referenced by ilCachedObjectDefinition\getInstance().

327  : bool
328  {
329  if (!$this->isActive()) {
330  return false;
331  }
332  self::log($key . ' set in component ' . $this->getComponent(), ilGlobalCacheSettings::LOG_LEVEL_CHATTY);
333  $this->global_cache->setValid($key);
334 
335  return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
336  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setActive()

ilGlobalCache::setActive ( bool  $active)

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

References $active.

Referenced by __construct().

404  : void
405  {
406  $this->active = $active;
407  }
+ Here is the caller graph for this function:

◆ setActiveComponents()

static ilGlobalCache::setActiveComponents ( array  $active_components)
static

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

References $active_components.

439  : void
440  {
441  self::$active_components = $active_components;
442  }
static array $active_components

◆ setAvailableComponents()

static ilGlobalCache::setAvailableComponents ( array  $available_components)
static

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

References $available_components.

449  : void
450  {
451  self::$available_components = $available_components;
452  }
static array $available_components

◆ setComponent()

ilGlobalCache::setComponent ( string  $component)

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

References $component.

Referenced by __construct().

394  : void
395  {
396  $this->component = $component;
397  }
+ Here is the caller graph for this function:

◆ setServiceType()

ilGlobalCache::setServiceType ( int  $service_type)

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

References $service_type.

Referenced by __construct().

414  : void
415  {
416  $this->service_type = $service_type;
417  }
+ Here is the caller graph for this function:

◆ setSettings()

static ilGlobalCache::setSettings ( ilGlobalCacheSettings  $settings)
static

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

References $settings, and ILIAS\LTI\ToolProvider\$settings.

429  : void
430  {
432  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static ilGlobalCacheSettings $settings

◆ setup()

static ilGlobalCache::setup ( ilGlobalCacheSettings  $ilGlobalCacheSettings)
static

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

References ilGlobalCacheSettings\getActivatedComponents(), and ILIAS\LTI\ToolProvider\setSettings().

Referenced by ilInitialisation\initClientIniFile(), ilServicesGlobalCacheTest\testService(), and ilServicesGlobalCacheTest\testValues().

120  : void
121  {
122  self::setSettings($ilGlobalCacheSettings);
123  self::setActiveComponents($ilGlobalCacheSettings->getActivatedComponents());
124  }
setSettings(array $settings)
Set an array of all setting values.
Definition: System.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $active

bool ilGlobalCache::$active = true
protected

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

Referenced by getActive(), and setActive().

◆ $active_cache

array ilGlobalCache::$active_cache = array()
staticprotected

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

◆ $active_components

array ilGlobalCache::$active_components = array()
staticprotected

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

Referenced by setActiveComponents().

◆ $available_components

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

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

Referenced by setAvailableComponents().

◆ $available_types

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

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

◆ $component

string ilGlobalCache::$component = null
protected

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

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

◆ $global_cache

ilGlobalCacheService ilGlobalCache::$global_cache
protected

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

◆ $instances

array ilGlobalCache::$instances = null
staticprotected

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

◆ $service_type

int ilGlobalCache::$service_type = ilGlobalCache::TYPE_STATIC
protected

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

Referenced by getInstance(), getServiceType(), and setServiceType().

◆ $settings

ilGlobalCacheSettings ilGlobalCache::$settings = null
staticprotected

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

Referenced by setSettings().

◆ $type_per_component

array ilGlobalCache::$type_per_component = array()
staticprotected

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

◆ $types

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

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

Referenced by getAllInstallableTypes(), and getAllTypes().

◆ $unique_service_id

string ilGlobalCache::$unique_service_id = null
staticprotected

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

◆ ACTIVE

const ilGlobalCache::ACTIVE = true

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

◆ COMP_CLNG

const ilGlobalCache::COMP_CLNG = 'clng'

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

Referenced by ilCachedLanguage\__construct().

◆ COMP_EVENTS

const ilGlobalCache::COMP_EVENTS = 'events'

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

Referenced by ilAppEventHandler\initListeners().

◆ COMP_GLOBAL_SCREEN

◆ COMP_ILCTRL

const ilGlobalCache::COMP_ILCTRL = 'ilctrl'

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

◆ COMP_OBJ_DEF

◆ COMP_PLUGINS

const ilGlobalCache::COMP_PLUGINS = 'plugins'

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

◆ COMP_RBAC_UA

const ilGlobalCache::COMP_RBAC_UA = 'rbac_ua'

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

◆ COMP_TEMPLATE

const ilGlobalCache::COMP_TEMPLATE = 'tpl'

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

Referenced by HTML_Template_IT\getFile().

◆ COMP_TPL_BLOCKS

const ilGlobalCache::COMP_TPL_BLOCKS = 'tpl_blocks'

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

Referenced by HTML_Template_IT\init().

◆ COMP_TPL_VARIABLES

const ilGlobalCache::COMP_TPL_VARIABLES = 'tpl_variables'

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

◆ TYPE_APC

◆ TYPE_FALLBACK

const ilGlobalCache::TYPE_FALLBACK = self::TYPE_STATIC

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

◆ TYPE_MEMCACHED

◆ TYPE_STATIC


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