13 private static $MINSERVERVERSION =
'1.1.12';
23 private $expires = 86400;
44 if (!class_exists(
'Memcache')) {
49 $this->memcache =
new Memcache;
52 if (!$CONFIG->memcache_servers) {
53 throw new ConfigurationException(
'No memcache servers defined, please populate the $CONFIG->memcache_servers variable');
56 if (is_callable(array($this->memcache,
'addServer'))) {
57 foreach ($CONFIG->memcache_servers as $server) {
58 if (is_array($server)) {
59 $this->memcache->addServer(
61 isset($server[1]) ? $server[1] : 11211,
62 isset($server[2]) ? $server[2] :
false,
63 isset($server[3]) ? $server[3] : 1,
64 isset($server[4]) ? $server[4] : 1,
65 isset($server[5]) ? $server[5] : 15,
66 isset($server[6]) ? $server[6] :
true 70 $this->memcache->addServer($server, 11211);
77 elgg_log(
"This version of the PHP memcache API doesn't support multiple servers.",
'ERROR');
79 $server = $CONFIG->memcache_servers[0];
80 if (is_array($server)) {
81 $this->memcache->connect($server[0], $server[1]);
83 $this->memcache->addServer($server, 11211);
88 $this->
version = $this->memcache->getVersion();
89 if (version_compare($this->
version, ElggMemcache::$MINSERVERVERSION,
'<')) {
90 $msg = vsprintf(
'Memcache needs at least version %s to run, you are running %s',
91 array(ElggMemcache::$MINSERVERVERSION,
99 if (isset($CONFIG->memcache_expires)) {
100 $this->expires = $CONFIG->memcache_expires;
112 $this->expires = $expires;
123 private function makeMemcacheKey(
$key) {
126 if (strlen($prefix .
$key) > 250) {
130 return $prefix .
$key;
143 $key = $this->makeMemcacheKey(
$key);
145 if ($expires === null) {
146 $expires = $this->expires;
151 elgg_log(
"MEMCACHE: SAVE FAIL $key",
'ERROR');
153 elgg_log(
"MEMCACHE: SAVE SUCCESS $key",
'INFO');
169 $key = $this->makeMemcacheKey(
$key);
173 elgg_log(
"MEMCACHE: LOAD MISS $key",
'INFO');
175 elgg_log(
"MEMCACHE: LOAD HIT $key",
'INFO');
189 $key = $this->makeMemcacheKey(
$key);
191 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.
elgg_log($message, $level= 'NOTICE')
Display or log a message.