ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilMemcache.php
Go to the documentation of this file.
1<?php
2
3require_once('./Services/GlobalCache/classes/class.ilGlobalCacheService.php');
4
12
13 const STD_SERVER = '127.0.0.1';
14 const STD_PORT = 11211;
18 protected static $servers = array(
19 self::STD_SERVER => self::STD_PORT,
20 );
24 protected static $memcache_object;
25
26
32 if (! (self::$memcache_object instanceof Memcached) AND $this->getInstallable()) {
33 $memcached = new Memcached();
34 foreach (self::$servers as $host => $port) {
35 $memcached->addServer($host, $port);
36 }
37 self::$memcache_object = $memcached;
38 }
39 parent::__construct($service_id, $component);
40 }
41
42
46 protected function getMemcacheObject() {
48 }
49
50
56 public function exists($key) {
57 return $this->getMemcacheObject()->get($this->returnKey($key)) != NULL;
58 }
59
60
68 public function set($key, $serialized_value, $ttl = NULL) {
69 return $this->getMemcacheObject()->set($this->returnKey($key), $serialized_value, $ttl);
70 }
71
72
78 public function get($key) {
79 return $this->getMemcacheObject()->get($this->returnKey($key));
80 }
81
82
88 public function delete($key) {
89 return $this->getMemcacheObject()->delete($this->returnKey($key));
90 }
91
92
96 public function flush() {
97 return $this->getMemcacheObject()->flush();
98 }
99
100
104 protected function getActive() {
105 if ($this->getInstallable()) {
106 $stats = $this->getMemcacheObject()->getStats();
107
108 return $stats[self::STD_SERVER . ':' . self::STD_PORT]['pid'] > 0;
109 }
110 }
111
112
116 protected function getInstallable() {
117 return class_exists('Memcached');
118 }
119
120
125 if ($this->getMemcacheObject() instanceof Memcached) {
126 $stats = $this->getMemcacheObject()->getStats();
127
128 if (! $stats[self::STD_SERVER . ':' . self::STD_PORT]['pid'] > 0) {
129 return 'No Memcached-Server available';
130 }
131 }
132
133 return parent::getInstallationFailureReason();
134 }
135
136
142 public function serialize($value) {
143 return serialize($value);
144 }
145
146
152 public function unserialize($serialized_value) {
153 return unserialize($serialized_value);
154 }
155
156
160 public function getInfo() {
161 if (self::isInstallable()) {
162 $return = array();
163 $return['__cache_info'] = $this->getMemcacheObject()->getStats();
164 foreach ($this->getMemcacheObject()->getAllKeys() as $key) {
165 $return[$key] = $this->getMemcacheObject()->get($key);
166 }
167
168 return $return;
169 }
170 }
171}
172
173?>
Class ilGlobalCacheService.
Class ilMemcache.
getInstallationFailureReason()
static $memcache_object
__construct($service_id, $component)
unserialize($serialized_value)