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';
64 self::COMP_TPL_BLOCKS,
65 self::COMP_TPL_VARIABLES,
106 self::setSettings($ilGlobalCacheSettings);
120 $ilGlobalCache->setComponent($component);
121 $ilGlobalCache->initCachingService();
123 self::$instances[
$component] = $ilGlobalCache;
135 self::generateServiceId();
140 protected function initCachingService() {
147 $serviceName = self::lookupServiceClassName($this->
getServiceType());
148 $ilGlobalCacheService =
new $serviceName(self::$unique_service_id, $this->
getComponent());
150 $this->global_cache = $ilGlobalCacheService;
158 $ilGlobalCacheSettings =
new ilGlobalCacheSettings();
167 public static function log($message, $log_level) {
168 if ($log_level <= self::getSettings()->getLogLevel()) {
171 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
172 $function = $backtrace[1][
'function'];
173 $class = $backtrace[1][
'class'];
175 $ilLog->alert($class .
'::' . $function .
'(): ' . $message);
185 if (!isset(self::$unique_service_id)) {
186 self::$unique_service_id = substr(md5(
'il_' . CLIENT_ID), 0, 6);
191 public static function flushAll() {
196 foreach (self::$types as $type) {
197 $serviceName = self::lookupServiceClassName($type);
198 $service =
new $serviceName(self::generateServiceId(),
'flush');
199 if ($service->isActive()) {
201 $returned = $service->flush();
213 foreach (self::getAllTypes() as $type) {
214 if ($type->isCacheServiceInstallable()) {
229 foreach (self::$types as $type) {
230 if ($only_available && !in_array($type, self::$available_types)) {
233 $obj =
new self($type);
234 $obj->initCachingService();
252 case self::TYPE_MEMCACHED:
255 case self::TYPE_XCACHE:
259 return 'ilStaticCache';
275 if (self::$active_cache[$this->
getComponent()] !== null) {
290 $isActive = $this->global_cache->isActive();
291 self::log(
'component ' . $this->
getComponent() .
', service is active: ' 305 return $this->global_cache->isValid($key);
313 return count(self::getAllInstallableTypes()) > 0;
321 return $this->global_cache->isInstallable();
329 return $this->global_cache->getInstallationFailureReason();
340 if (!$this->global_cache->isActive()) {
344 return $this->global_cache->exists($key);
356 public function set($key, $value, $ttl = null) {
361 $this->global_cache->setValid($key);
363 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
373 public function get($key) {
377 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
378 if ($unserialized_return) {
379 $service_name =
' [' . self::lookupServiceClassName($this->
getServiceType()) .
']';
380 if ($this->global_cache->isValid($key)) {
383 return $unserialized_return;
398 public function delete($key) {
403 return $this->global_cache->delete($key);
413 public function flush($complete =
false) {
414 if ($this->global_cache->isActive()) {
416 return $this->global_cache->flush();
418 $this->global_cache->setInvalid();
427 return $this->global_cache->getInfo();
479 return $this->global_cache->getServiceType();
506 return self::$active_components;
522 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
Create styles array
The data for the language used.
static log($message, $log_level)
getInstallationFailureReason()
static getActiveComponents()
static setSettings($settings)
static setAvailableComponents($available_components)