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');
15 const MSG =
'Global Cache not active, can not access cache';
90 protected static function getComponentType(
$component = NULL) {
92 if (!isset(self::$type_per_component[
$component])) {
96 global $ilClientIniFile;
97 if ($ilClientIniFile instanceof
ilIniFile) {
98 self::$type_per_component[
$component] = $ilClientIniFile->readVariable(
'cache',
'global_cache_service_type');
102 if (self::$type_per_component[$component]) {
120 self::$instances[
$component] = $ilGlobalCache;
131 if (!isset(self::$unique_service_id)) {
132 self::$unique_service_id = substr(md5(
'il_' . CLIENT_ID), 0, 6);
139 public static function flushAll() {
143 foreach (self::$types as $type) {
145 $service =
new $serviceName(self::generateServiceId(),
'flush');
146 if ($service->isActive()) {
158 foreach (self::getAllTypes() as $type) {
159 if ($type->isCacheServiceInstallable()) {
173 foreach (self::$types as $type) {
174 $obj =
new self($type);
192 $this->global_cache->setServiceType($service_type_id);
206 case self::TYPE_MEMCACHED:
209 case self::TYPE_XCACHE:
213 return 'ilStaticCache';
222 public function isActive() {
230 global $ilClientIniFile;
231 if ($ilClientIniFile instanceof
ilIniFile) {
232 if ($ilClientIniFile->readVariable(
'cache',
'activate_global_cache') !=
'1') {
242 return $this->global_cache->isActive();
252 return $this->global_cache->isValid($key);
260 return count(self::getAllInstallableTypes()) > 0;
268 return $this->global_cache->isInstallable();
276 return $this->global_cache->getInstallationFailureReason();
287 if (!$this->global_cache->isActive()) {
291 return $this->global_cache->exists($key);
303 public function set($key, $value, $ttl = NULL) {
304 if (!$this->isActive()) {
307 $this->global_cache->setValid($key);
309 return $this->global_cache->set($key, $this->global_cache->serialize($value), $ttl);
319 public function get($key) {
320 if (!$this->isActive()) {
323 $unserialized_return = $this->global_cache->unserialize($this->global_cache->get($key));
324 if ($unserialized_return) {
326 if ($this->global_cache->isValid($key)) {
328 return $unserialized_return;
344 public function delete($key) {
345 if (!$this->isActive()) {
348 throw new RuntimeException(self::MSG);
351 return $this->global_cache->delete($key);
361 public function flush($complete =
false) {
362 if ($this->global_cache->isActive()) {
364 return $this->global_cache->flush();
366 $this->global_cache->setInvalid();
375 return $this->global_cache->getInfo();
439 return $this->global_cache->getServiceType();