summaryrefslogtreecommitdiff
path: root/lib/cache.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-16 09:22:02 -0800
committerBrion Vibber <brion@pobox.com>2010-02-16 09:22:02 -0800
commit81b6b58e33f55054b7e5dd546f06dbdb5696ed92 (patch)
tree7dddea4daac884f70d021fb11f1d02d560c0cd10 /lib/cache.php
parent2e258454f396af9f95092b9564eee08179ff6be1 (diff)
parentc74aea589d5a79d7048470d44e457dffc8919ad3 (diff)
Merge branch 'master' into testing
Conflicts: lib/stompqueuemanager.php
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