From e5dd77ea26178d71770005f4855abc5a355d5a7b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 25 Jul 2016 12:27:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=B1=BB=E5=A2=9E=E5=8A=A0in?= =?UTF-8?q?c=E5=92=8Cdec=E6=96=B9=E6=B3=95=20=E9=92=88=E5=AF=B9=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E5=9E=8B=E6=95=B0=E6=8D=AE=E6=8F=90=E4=BE=9B=E8=87=AA?= =?UTF-8?q?=E5=A2=9E=E5=92=8C=E8=87=AA=E5=87=8F=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 32 +++++++++++++++++++++ library/think/cache/driver/File.php | 36 ++++++++++++++++++++++++ library/think/cache/driver/Lite.php | 36 ++++++++++++++++++++++++ library/think/cache/driver/Memcache.php | 26 +++++++++++++++++ library/think/cache/driver/Memcached.php | 26 +++++++++++++++++ library/think/cache/driver/Sqlite.php | 36 ++++++++++++++++++++++++ library/think/cache/driver/Wincache.php | 26 +++++++++++++++++ library/think/cache/driver/Xcache.php | 26 +++++++++++++++++ 8 files changed, 244 insertions(+) diff --git a/library/think/Cache.php b/library/think/Cache.php index f13f511c..10ff01c8 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -110,6 +110,36 @@ class Cache return self::$handler->set($name, $value, $expire); } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + self::init(); + self::$writeTimes++; + return self::$handler->inc($name, $step, $expire); + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + self::init(); + self::$writeTimes++; + return self::$handler->dec($name, $step, $expire); + } + /** * 删除缓存 * @access public @@ -119,6 +149,7 @@ class Cache public static function rm($name) { self::init(); + self::$writeTimes++; return self::$handler->rm($name); } @@ -130,6 +161,7 @@ class Cache public static function clear() { self::init(); + self::$writeTimes++; return self::$handler->clear(); } diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 19d42005..c356f21c 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -158,6 +158,42 @@ class File } } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) + $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) - $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + /** * 删除缓存 * @access public diff --git a/library/think/cache/driver/Lite.php b/library/think/cache/driver/Lite.php index ab295672..e83f73e4 100644 --- a/library/think/cache/driver/Lite.php +++ b/library/think/cache/driver/Lite.php @@ -113,6 +113,42 @@ class Lite return $ret; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) + $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) - $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + /** * 删除缓存 * @access public diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcache.php index 73b6b008..49b67454 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcache.php @@ -100,6 +100,32 @@ class Memcache return false; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + return $this->handler->increment($name, $step, $expire); + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + return $this->handler->decrement($name, $step, $expire); + } + /** * 删除缓存 * @param string $name 缓存变量名 diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index 4140a842..6b800c1e 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -106,6 +106,32 @@ class Memcached return false; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + return $this->handler->increment($name, $step, $expire); + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + return $this->handler->decrement($name, $step, $expire); + } + /** * 删除缓存 * @param string $name 缓存变量名 diff --git a/library/think/cache/driver/Sqlite.php b/library/think/cache/driver/Sqlite.php index 561acdfc..6814773a 100644 --- a/library/think/cache/driver/Sqlite.php +++ b/library/think/cache/driver/Sqlite.php @@ -110,6 +110,42 @@ class Sqlite return false; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) + $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + if ($this->has($name)) { + $value = $this->get($name) - $step; + } else { + $value = $step; + } + return $this->set($name, $value, $expire) ? $value : false; + } + /** * 删除缓存 * @access public diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index 5556162c..940ecc4e 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -85,6 +85,32 @@ class Wincache return false; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + return wincache_ucache_inc($name, $step, $expire); + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + return wincache_ucache_dec($name, $step, $expire); + } + /** * 删除缓存 * @access public diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index 6c7b9c95..99b01f6b 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -85,6 +85,32 @@ class Xcache return false; } + /** + * 自增缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function inc($name, $step = 1, $expire = null) + { + return xcache_inc($name, $step, $expire); + } + + /** + * 自减缓存(针对数值缓存) + * @access public + * @param string $name 缓存变量名 + * @param int $step 步长 + * @param int $expire 有效时间 0为永久 + * @return false|int + */ + public function dec($name, $step = 1, $expire = null) + { + return xcache_dec($name, $step, $expire); + } + /** * 删除缓存 * @access public