summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache/drivers/Cache_wincache.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-09 16:29:45 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-09 16:29:45 +0100
commit43d7fa73534c07d10a88ec120c0938d0d00a184e (patch)
tree84cc278c1d199da4e8d1dc4d7999cdbc174fc732 /system/libraries/Cache/drivers/Cache_wincache.php
parent40235e6890650690afeaa451738bf7f8e586cfc3 (diff)
Implement atomic increment/decrement in Cache library
Requested via issue #109 Supersedes PR #241
Diffstat (limited to 'system/libraries/Cache/drivers/Cache_wincache.php')
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php47
1 files changed, 41 insertions, 6 deletions
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index 80d3ac13d..25c18ab58 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -46,8 +46,8 @@ class CI_Cache_wincache extends CI_Driver {
* Look for a value in the cache. If it exists, return the data,
* if not, return FALSE
*
- * @param string
- * @return mixed value that is stored/FALSE on failure
+ * @param string $id Cache Ide
+ * @return mixed Value that is stored/FALSE on failure
*/
public function get($id)
{
@@ -63,12 +63,13 @@ class CI_Cache_wincache extends CI_Driver {
/**
* Cache Save
*
- * @param string Unique Key
- * @param mixed Data to store
- * @param int Length of time (in seconds) to cache the data
+ * @param string $id Cache ID
+ * @param mixed $data Data to store
+ * @param int $ttl Time to live (in seconds)
+ * @param bool $raw Whether to store the raw value (unused)
* @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 wincache_ucache_set($id, $data, $ttl);
}
@@ -89,6 +90,40 @@ class CI_Cache_wincache extends CI_Driver {
// ------------------------------------------------------------------------
/**
+ * 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)
+ {
+ $success = FALSE;
+ $value = wincache_ucache_inc($id, $offset, $success);
+
+ return ($success === TRUE) ? $value : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * 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)
+ {
+ $success = FALSE;
+ $value = wincache_ucache_dec($id, $offset, $success);
+
+ return ($success === TRUE) ? $value : FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Clean the cache
*
* @return bool false on failure/true on success