diff options
author | Andrey Andreev <narf@devilix.net> | 2014-01-09 16:29:45 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-01-09 16:29:45 +0100 |
commit | 43d7fa73534c07d10a88ec120c0938d0d00a184e (patch) | |
tree | 84cc278c1d199da4e8d1dc4d7999cdbc174fc732 /system/libraries/Cache/Cache.php | |
parent | 40235e6890650690afeaa451738bf7f8e586cfc3 (diff) |
Implement atomic increment/decrement in Cache library
Requested via issue #109
Supersedes PR #241
Diffstat (limited to 'system/libraries/Cache/Cache.php')
-rw-r--r-- | system/libraries/Cache/Cache.php | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 537897eaf..2dffa350c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -150,14 +150,15 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string $id Cache ID - * @param mixed $data Data to store - * @param int $ttl = 60 Cache TTL (in seconds) + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Cache TTL (in seconds) + * @param bool $raw Whether to store the raw value * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { - return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl); + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); } // ------------------------------------------------------------------------ @@ -176,6 +177,34 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->{$this->_adapter}->increment($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->{$this->_adapter}->decrement($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** * Clean the cache * * @return bool TRUE on success, FALSE on failure |