2 require_once(
'./Services/GlobalCache/classes/Memcache/class.ilMemcache.php');
3 require_once(
'./Services/GlobalCache/classes/Xcache/class.ilXcache.php');
4 require_once(
'./Services/GlobalCache/classes/Apc/class.ilApc.php');
5 require_once(
'./Services/GlobalCache/classes/Static/class.ilStaticCache.php');
6 require_once(
'Settings/class.ilGlobalCacheSettings.php');
15 const MSG =
'Global Cache not active, can not access cache';
64 self::COMP_TPL_BLOCKS,
65 self::COMP_TPL_VARIABLES,
67 self::COMP_GLOBAL_SCREEN,
107 self::setSettings($ilGlobalCacheSettings);
120 $ilGlobalCache->setComponent($component);
121 $ilGlobalCache->initCachingService();
123 self::$instances[
$component] = $ilGlobalCache;
135 self::generateServiceId();
139 protected function initCachingService()
147 $serviceName = self::lookupServiceClassName($this->
getServiceType());
148 $ilGlobalCacheService =
new $serviceName(self::$unique_service_id, $this->
getComponent());
150 $this->global_cache = $ilGlobalCacheService;
157 $ilGlobalCacheSettings =
new ilGlobalCacheSettings();
167 if ($log_level <= self::getSettings()->getLogLevel()) {
169 $ilLog = $DIC[
'ilLog'];
170 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
171 $function = $backtrace[1][
'function'];
172 $class = $backtrace[1][
'class'];
174 $ilLog->alert($class .
'::' . $function .
'(): ' .
$message);
184 if (!isset(self::$unique_service_id)) {
186 if (defined(
'CLIENT_ID')) {
189 self::$unique_service_id = substr(md5($rawServiceId), 0, 6);
193 public static function flushAll()
199 foreach (self::$types as
$type) {
200 $serviceName = self::lookupServiceClassName($type);
201 $service =
new $serviceName(self::generateServiceId(),
'flush');
216 foreach (self::getAllTypes() as
$type) {
217 if ($type->isCacheServiceInstallable()) {
232 foreach (self::$types as
$type) {
233 if ($only_available && !in_array($type, self::$available_types)) {
236 $obj =
new self(
$type);
237 $obj->initCachingService();
249 case self::TYPE_MEMCACHED:
250 return ilMemcache::class;
251 case self::TYPE_XCACHE:
252 return ilXcache::class;
254 return ilStaticCache::class;
260 switch ($service_type) {
263 case self::TYPE_MEMCACHED:
265 case self::TYPE_XCACHE:
283 if (isset(self::$active_cache[
$c]) && self::$active_cache[$c] !== null) {
284 return self::$active_cache[
$c];
287 self::$active_cache[
$c] =
false;
293 self::$active_cache[
$c] =
false;
298 $isActive = $this->global_cache->isActive();
299 self::log(
'component ' . $c .
', service is active: ' 301 self::$active_cache[
$c] = $isActive;
312 return $this->global_cache->isValid($key);
320 return count(self::getAllInstallableTypes()) > 0;
328 return $this->global_cache->isInstallable();
336 return $this->global_cache->getInstallationFailureReason();
346 if (!$this->global_cache->isActive()) {
350 return $this->global_cache->exists($key);
360 public function set($key, $value, $ttl = null)
366 $this->global_cache->setValid($key);
368 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
376 public function get($key)
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)) {
387 return $unserialized_return;
400 public function delete($key)
406 return $this->global_cache->delete($key);
414 public function flush($complete =
false)
416 if ($this->global_cache->isActive()) {
417 return $this->global_cache->flush($complete);
425 return $this->global_cache->getInfo();
477 return $this->global_cache->getServiceType();
504 return self::$active_components;
520 return self::$available_components;
static setActiveComponents($active_components)
static getAllInstallableTypes()
Class ilGlobalCacheSettings.
static getInstance($component)
static setup(ilGlobalCacheSettings $ilGlobalCacheSettings)
static getAllTypes($only_available=true)
Component logger with individual log levels by component id.
Class ilGlobalCacheService.
setServiceType($service_type)
static generateServiceId()
__construct($service_type)
static $available_components
static lookupServiceClassName($service_type)
static $unique_service_id
isCacheServiceInstallable()
static getAvailableComponents()
static $type_per_component
static $active_components
static log($message, $log_level)
getInstallationFailureReason()
static lookupServiceConfigName(int $service_type)
static getActiveComponents()
static setSettings($settings)
static setAvailableComponents($available_components)