From e5af2c34a5af6a6e505034e9af6248131eaf7925 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Mon, 25 Dec 2017 19:38:59 +0800 Subject: Setting initial value with increment/decrement functions. Signed-off-by: tianhe1986 --- system/libraries/Cache/drivers/Cache_memcached.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 4836b6aed..314263d7e 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -210,6 +210,7 @@ class CI_Cache_memcached extends CI_Driver { */ public function increment($id, $offset = 1) { + $this->_memcached->add($id, 0); return $this->_memcached->increment($id, $offset); } @@ -224,6 +225,7 @@ class CI_Cache_memcached extends CI_Driver { */ public function decrement($id, $offset = 1) { + $this->_memcached->add($id, 0); return $this->_memcached->decrement($id, $offset); } -- cgit v1.2.3-24-g4f1b From 89da3a5bf7a87bcbc922ed4b57ba26e875807dba Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Tue, 2 Jan 2018 17:40:56 +0800 Subject: Calling add() after increment/decrement when the return value is FALSE. Signed-off-by: tianhe1986 --- system/libraries/Cache/drivers/Cache_memcached.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 314263d7e..cbf874b97 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -210,8 +210,13 @@ class CI_Cache_memcached extends CI_Driver { */ public function increment($id, $offset = 1) { - $this->_memcached->add($id, 0); - return $this->_memcached->increment($id, $offset); + if (($result = $this->_memcached->increment($id, $offset)) === FALSE) + { + $this->_memcached->add($id, 0); + $result = $this->_memcached->increment($id, $offset); + } + + return $result; } // ------------------------------------------------------------------------ @@ -225,8 +230,13 @@ class CI_Cache_memcached extends CI_Driver { */ public function decrement($id, $offset = 1) { - $this->_memcached->add($id, 0); - return $this->_memcached->decrement($id, $offset); + if (($result = $this->_memcached->decrement($id, $offset)) === FALSE) + { + $this->_memcached->add($id, 0); + $result = $this->_memcached->decrement($id, $offset); + } + + return $result; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From f87fb6dd6c5406029bb1a26d6ba6933d4a69d26e Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Thu, 4 Jan 2018 17:10:50 +0800 Subject: Calling another increment/decrement if add() return FALSE. Signed-off-by: tianhe1986 --- system/libraries/Cache/drivers/Cache_memcached.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index cbf874b97..8b6af84db 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -212,8 +212,7 @@ class CI_Cache_memcached extends CI_Driver { { if (($result = $this->_memcached->increment($id, $offset)) === FALSE) { - $this->_memcached->add($id, 0); - $result = $this->_memcached->increment($id, $offset); + return $this->_memcached->add($id, $offset) ? $offset : $this->_memcached->increment($id, $offset); } return $result; @@ -232,8 +231,7 @@ class CI_Cache_memcached extends CI_Driver { { if (($result = $this->_memcached->decrement($id, $offset)) === FALSE) { - $this->_memcached->add($id, 0); - $result = $this->_memcached->decrement($id, $offset); + return $this->_memcached->add($id, 0) ? 0 : $this->_memcached->decrement($id, $offset); } return $result; -- cgit v1.2.3-24-g4f1b From d77ceeaf3d7c506a050163af40f4a6bb1e1f2a38 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Fri, 5 Jan 2018 22:50:05 +0800 Subject: Do not retry after calling add() Signed-off-by: tianhe1986 --- system/libraries/Cache/drivers/Cache_memcached.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 8b6af84db..1562569e8 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -212,7 +212,7 @@ class CI_Cache_memcached extends CI_Driver { { if (($result = $this->_memcached->increment($id, $offset)) === FALSE) { - return $this->_memcached->add($id, $offset) ? $offset : $this->_memcached->increment($id, $offset); + return $this->_memcached->add($id, $offset) ? $offset : FALSE; } return $result; @@ -231,7 +231,7 @@ class CI_Cache_memcached extends CI_Driver { { if (($result = $this->_memcached->decrement($id, $offset)) === FALSE) { - return $this->_memcached->add($id, 0) ? 0 : $this->_memcached->decrement($id, $offset); + return $this->_memcached->add($id, 0) ? 0 : FALSE; } return $result; -- cgit v1.2.3-24-g4f1b