mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
缓存类增加inc和dec方法 针对数值型数据提供自增和自减操作
This commit is contained in:
@@ -110,6 +110,36 @@ class Cache
|
|||||||
return self::$handler->set($name, $value, $expire);
|
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
|
* @access public
|
||||||
@@ -119,6 +149,7 @@ class Cache
|
|||||||
public static function rm($name)
|
public static function rm($name)
|
||||||
{
|
{
|
||||||
self::init();
|
self::init();
|
||||||
|
self::$writeTimes++;
|
||||||
return self::$handler->rm($name);
|
return self::$handler->rm($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +161,7 @@ class Cache
|
|||||||
public static function clear()
|
public static function clear()
|
||||||
{
|
{
|
||||||
self::init();
|
self::init();
|
||||||
|
self::$writeTimes++;
|
||||||
return self::$handler->clear();
|
return self::$handler->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
library/think/cache/driver/File.php
vendored
36
library/think/cache/driver/File.php
vendored
@@ -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
|
* @access public
|
||||||
|
|||||||
36
library/think/cache/driver/Lite.php
vendored
36
library/think/cache/driver/Lite.php
vendored
@@ -113,6 +113,42 @@ class Lite
|
|||||||
return $ret;
|
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
|
* @access public
|
||||||
|
|||||||
26
library/think/cache/driver/Memcache.php
vendored
26
library/think/cache/driver/Memcache.php
vendored
@@ -100,6 +100,32 @@ class Memcache
|
|||||||
return false;
|
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 缓存变量名
|
* @param string $name 缓存变量名
|
||||||
|
|||||||
26
library/think/cache/driver/Memcached.php
vendored
26
library/think/cache/driver/Memcached.php
vendored
@@ -106,6 +106,32 @@ class Memcached
|
|||||||
return false;
|
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 缓存变量名
|
* @param string $name 缓存变量名
|
||||||
|
|||||||
36
library/think/cache/driver/Sqlite.php
vendored
36
library/think/cache/driver/Sqlite.php
vendored
@@ -110,6 +110,42 @@ class Sqlite
|
|||||||
return false;
|
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
|
* @access public
|
||||||
|
|||||||
26
library/think/cache/driver/Wincache.php
vendored
26
library/think/cache/driver/Wincache.php
vendored
@@ -85,6 +85,32 @@ class Wincache
|
|||||||
return false;
|
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
|
* @access public
|
||||||
|
|||||||
26
library/think/cache/driver/Xcache.php
vendored
26
library/think/cache/driver/Xcache.php
vendored
@@ -85,6 +85,32 @@ class Xcache
|
|||||||
return false;
|
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
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user