aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/memcache.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-04 17:36:38 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-04 17:36:38 +0000
commitc21cf65787e4f5f3994104a90c7291eb6fc5f60a (patch)
tree4416fa63d5bdae98834797e2c72758c9ba378dd0 /engine/lib/memcache.php
parent81152e9e57332eeb78692c33a96b161ed92fb2ed (diff)
downloadelgg-c21cf65787e4f5f3994104a90c7291eb6fc5f60a.tar.gz
elgg-c21cf65787e4f5f3994104a90c7291eb6fc5f60a.tar.bz2
Experimental memcache support
git-svn-id: https://code.elgg.org/elgg/trunk@2399 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/memcache.php')
-rw-r--r--engine/lib/memcache.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/engine/lib/memcache.php b/engine/lib/memcache.php
index b50c3c820..c5618b71d 100644
--- a/engine/lib/memcache.php
+++ b/engine/lib/memcache.php
@@ -34,9 +34,9 @@
private $memcache;
/**
- * Expiry of saved items (defaults forever)
+ * Expiry of saved items (default timeout after an hour to prevent anything getting too stale)
*/
- private $expires = 0;
+ private $expires = 3600;
/**
* The version of memcache running
@@ -150,6 +150,7 @@
$key = $this->make_memcache_key($key);
$this->keys_so_far[$key] = time();
+ $this->save_persistent_keylist();
$result = $this->memcache->set($key, $data, null, $this->expires);
if ((isset($CONFIG->debug)) && ($CONFIG->debug == true) && (!$result))
@@ -163,6 +164,7 @@
$key = $this->make_memcache_key($key);
$this->keys_so_far[$key] = time();
+ $this->save_persistent_keylist();
$result = $this->memcache->get($key);
if ((isset($CONFIG->debug)) && ($CONFIG->debug == true) && (!$result))
@@ -183,9 +185,32 @@
foreach ($this->keys_so_far as $key => $ts)
$this->memcache->delete($key, 0);
+ $this->clear_persistent_keylist();
$this->keys_so_far = array();
return true;
}
+
+ private function load_persistent_keylist()
+ {
+ return $this->memcache->get($this->namespace.':keys_so_far');
+ }
+
+ private function save_persistent_keylist()
+ {
+ $stored = $this->load_persistent_keylist();
+ if ($stored) $this->keys_so_far = array_merge($this->keys_so_far, $stored);
+ return $this->memcache->set($this->namespace.':keys_so_far', $this->keys_so_far, null, 0);
+ }
+
+ private function clear_persistent_keylist()
+ {
+ return $this->memcache->delete($this->namespace.':keys_so_far', 0);
+ }
+
+ public function __destruct()
+ {
+ $this->save_persistent_keylist();
+ }
}
?> \ No newline at end of file