20 private static $MINSERVERVERSION =
'1.1.12';
30 private $expires = 86400;
47 $this->CONFIG = $CONFIG;
52 if (!class_exists(
'Memcache')) {
53 throw new \ConfigurationException(
'PHP memcache module not installed, you must install php5-memcache');
57 $this->memcache =
new Memcache;
60 if (!$this->CONFIG->memcache_servers) {
61 throw new \ConfigurationException(
'No memcache servers defined, please populate the $this->CONFIG->memcache_servers variable');
64 if (is_callable(array($this->memcache,
'addServer'))) {
65 foreach ($this->CONFIG->memcache_servers as $server) {
66 if (is_array($server)) {
67 $this->memcache->addServer(
69 isset($server[1]) ? $server[1] : 11211,
70 isset($server[2]) ? $server[2] :
false,
71 isset($server[3]) ? $server[3] : 1,
72 isset($server[4]) ? $server[4] : 1,
73 isset($server[5]) ? $server[5] : 15,
74 isset($server[6]) ? $server[6] :
true 78 $this->memcache->addServer($server, 11211);
85 _elgg_services()->logger->error(
"This version of the PHP memcache API doesn't support multiple servers.");
87 $server = $this->CONFIG->memcache_servers[0];
88 if (is_array($server)) {
89 $this->memcache->connect($server[0], $server[1]);
91 $this->memcache->addServer($server, 11211);
96 $this->
version = $this->memcache->getVersion();
97 if (version_compare($this->
version, \ElggMemcache::$MINSERVERVERSION,
'<')) {
98 $msg = vsprintf(
'Memcache needs at least version %s to run, you are running %s',
99 array(\ElggMemcache::$MINSERVERVERSION,
103 throw new \ConfigurationException($msg);
107 if (isset($this->CONFIG->memcache_expires)) {
108 $this->expires = $this->CONFIG->memcache_expires;
120 $this->expires = $expires;
131 private function makeMemcacheKey(
$key) {
134 if (strlen($prefix .
$key) > 250) {
138 return $prefix .
$key;
151 $key = $this->makeMemcacheKey(
$key);
153 if ($expires === null) {
154 $expires = $this->expires;
177 $key = $this->makeMemcacheKey(
$key);
197 $key = $this->makeMemcacheKey(
$key);
199 return $this->memcache->delete(
$key, 0);
clear()
Clears the entire cache?
getNamespace()
Get the namespace currently defined.
setDefaultExpiry($expires=0)
Set the default expiry.
load($key, $offset=0, $limit=null)
Retrieves data.
__construct($namespace= 'default')
Connect to memcache.
setNamespace($namespace="default")
Set the namespace of this cache.
save($key, $data, $expires=null)
Saves a name and value to the cache.
elgg global
Pointer to the global context.