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()) {
170 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
171 $function = $backtrace[1][
'function'];
172 $class = $backtrace[1][
'class'];
184 if (!isset(self::$unique_service_id)) {
186 if (defined(
'CLIENT_ID')) {
187 $rawServiceId .=
'il_' . 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');
202 if ($service->isActive()) {
204 $returned = $service->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();
254 case self::TYPE_MEMCACHED:
257 case self::TYPE_XCACHE:
261 return 'ilStaticCache';
277 if (isset(self::$active_cache[
$c]) && self::$active_cache[$c] !== null) {
278 return self::$active_cache[
$c];
281 self::$active_cache[
$c] =
false;
287 self::$active_cache[
$c] =
false;
292 $isActive = $this->global_cache->isActive();
293 self::log(
'component ' . $c .
', service is active: ' 295 self::$active_cache[
$c] = $isActive;
306 return $this->global_cache->isValid(
$key);
314 return count(self::getAllInstallableTypes()) > 0;
322 return $this->global_cache->isInstallable();
330 return $this->global_cache->getInstallationFailureReason();
340 if (!$this->global_cache->isActive()) {
344 return $this->global_cache->exists(
$key);
354 public function set(
$key, $value, $ttl = null)
360 $this->global_cache->setValid(
$key);
362 return $this->global_cache->set(
$key, $this->global_cache->serialize($value), $ttl);
375 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get(
$key));
376 if ($unserialized_return) {
377 $service_name =
' [' . self::lookupServiceClassName($this->
getServiceType()) .
']';
378 if ($this->global_cache->isValid(
$key)) {
381 return $unserialized_return;
400 return $this->global_cache->delete(
$key);
408 public function flush($complete =
false)
410 if ($this->global_cache->isActive()) {
411 return $this->global_cache->flush($complete);
419 return $this->global_cache->getInfo();
471 return $this->global_cache->getServiceType();
498 return self::$active_components;
514 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
catch(Exception $e) $message
isCacheServiceInstallable()
static getAvailableComponents()
static $type_per_component
static $active_components
static log($message, $log_level)
getInstallationFailureReason()
static getActiveComponents()
static setSettings($settings)
static setAvailableComponents($available_components)