[ci skip] Merge pull request #5369 from tianhe1986/develop_cache_memcache
Cache_memcached: setting initial value with increment/decrement when not exist
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index b642a2c..ef020f2 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -198,7 +198,12 @@
*/
public function increment($id, $offset = 1)
{
- return $this->_memcached->increment($id, $offset);
+ if (($result = $this->_memcached->increment($id, $offset)) === FALSE)
+ {
+ return $this->_memcached->add($id, $offset) ? $offset : FALSE;
+ }
+
+ return $result;
}
// ------------------------------------------------------------------------
@@ -212,7 +217,12 @@
*/
public function decrement($id, $offset = 1)
{
- return $this->_memcached->decrement($id, $offset);
+ if (($result = $this->_memcached->decrement($id, $offset)) === FALSE)
+ {
+ return $this->_memcached->add($id, 0) ? 0 : FALSE;
+ }
+
+ return $result;
}
// ------------------------------------------------------------------------