summaryrefslogtreecommitdiff
path: root/lib/cache.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-16 12:46:02 -0500
committerEvan Prodromou <evan@status.net>2010-02-16 12:46:02 -0500
commit3d170bfa30168280a9c11e944f886460d7cc18c7 (patch)
tree0d99d6164fce4b35ceeff86acdda21722f4681e3 /lib/cache.php
parent71ecd689019a8086570c677af47ead4e02227fb3 (diff)
parent81b6b58e33f55054b7e5dd546f06dbdb5696ed92 (diff)
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'lib/cache.php')
-rw-r--r--lib/cache.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/cache.php b/lib/cache.php
index df6fc3649..c09a1dd9f 100644
--- a/lib/cache.php
+++ b/lib/cache.php
@@ -160,6 +160,32 @@ class Cache
}
/**
+ * Atomically increment an existing numeric value.
+ * Existing expiration time should remain unchanged, if any.
+ *
+ * @param string $key The key to use for lookups
+ * @param int $step Amount to increment (default 1)
+ *
+ * @return mixed incremented value, or false if not set.
+ */
+ function increment($key, $step=1)
+ {
+ $value = false;
+ if (Event::handle('StartCacheIncrement', array(&$key, &$step, &$value))) {
+ // Fallback is not guaranteed to be atomic,
+ // and may original expiry value.
+ $value = $this->get($key);
+ if ($value !== false) {
+ $value += $step;
+ $ok = $this->set($key, $value);
+ $got = $this->get($key);
+ }
+ Event::handle('EndCacheIncrement', array($key, $step, $value));
+ }
+ return $value;
+ }
+
+ /**
* Delete the value associated with a key
*
* @param string $key Key to delete