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');
16 const MSG =
'Global Cache not active, can not access cache';
55 self::COMP_TPL_BLOCKS,
56 self::COMP_TPL_VARIABLES,
97 self::setSettings($ilGlobalCacheSettings);
111 $ilGlobalCache->setComponent($component);
112 $ilGlobalCache->initCachingService();
114 self::$instances[
$component] = $ilGlobalCache;
126 self::generateServiceId();
131 protected function initCachingService() {
138 $serviceName = self::lookupServiceClassName($this->
getServiceType());
139 $ilGlobalCacheService =
new $serviceName(self::$unique_service_id, $this->
getComponent());
141 $this->global_cache = $ilGlobalCacheService;
149 $ilGlobalCacheSettings =
new ilGlobalCacheSettings();
158 public static function log($message, $log_level) {
159 if ($log_level <= self::getSettings()->getLogLevel()) {
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);
175 if (! isset(self::$unique_service_id)) {
176 self::$unique_service_id = substr(md5(
'il_' . CLIENT_ID), 0, 6);
181 public static function flushAll() {
186 foreach (self::$types as $type) {
187 $serviceName = self::lookupServiceClassName($type);
188 $service =
new $serviceName(self::generateServiceId(),
'flush');
189 if ($service->isActive()) {
191 $returned = $service->flush();
203 foreach (self::getAllTypes() as $type) {
204 if ($type->isCacheServiceInstallable()) {
218 foreach (self::$types as $type) {
219 $obj =
new self($type);
220 $obj->initCachingService();
238 case self::TYPE_MEMCACHED:
241 case self::TYPE_XCACHE:
245 return 'ilStaticCache';
261 if (self::$active_cache[$this->
getComponent()] !== NULL) {
264 if (! self::ACTIVE) {
276 $isActive = $this->global_cache->isActive();
277 self::log(
'component ' . $this->
getComponent() .
', service is active: ' 291 return $this->global_cache->isValid($key);
299 return count(self::getAllInstallableTypes()) > 0;
307 return $this->global_cache->isInstallable();
315 return $this->global_cache->getInstallationFailureReason();
326 if (! $this->global_cache->isActive()) {
330 return $this->global_cache->exists($key);
342 public function set($key, $value, $ttl = NULL) {
347 $this->global_cache->setValid($key);
349 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
359 public function get($key) {
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)) {
369 return $unserialized_return;
384 public function delete($key) {
389 return $this->global_cache->delete($key);
399 public function flush($complete =
false) {
400 if ($this->global_cache->isActive()) {
402 return $this->global_cache->flush();
404 $this->global_cache->setInvalid();
413 return $this->global_cache->getInfo();
465 return $this->global_cache->getServiceType();
492 return self::$active_components;
508 return self::$available_components;
static setActiveComponents($active_components)
static getAllInstallableTypes()
Class ilGlobalCacheSettings.
static getInstance($component)
static setup(ilGlobalCacheSettings $ilGlobalCacheSettings)
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 getActiveComponents()
static setSettings($settings)
static setAvailableComponents($available_components)