缓存驱动类调整

This commit is contained in:
thinkphp
2016-01-04 17:57:42 +08:00
parent 91ac44c85d
commit c8a5a03cf4
11 changed files with 38 additions and 23 deletions

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -27,7 +28,7 @@ class Apc
];
/*****************************
需要支持apc_cli模式
******************************/
******************************/
/**
* 架构函数
*
@@ -54,7 +55,7 @@ class Apc
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
return apc_fetch($this->options['prefix'] . $name);
}
@@ -68,7 +69,7 @@ class Apc
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,8 @@
namespace think\cache\driver;
use think\Cache;
/**
* 数据库方式缓存驱动
* CREATE TABLE think_cache (
@@ -55,7 +57,7 @@ class Db
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$name = $this->options['prefix'] . addslashes($name);
$result = $this->handler->query('SELECT `data`,`datacrc` FROM `' . $this->options['table'] . '` WHERE `cachekey`=\'' . $name . '\' AND (`expire` =0 OR `expire`>' . time() . ') LIMIT 0,1');
if (false !== $result) {
@@ -82,7 +84,7 @@ class Db
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
$data = serialize($value);
$name = $this->options['prefix'] . addslashes($name);
if (function_exists('gzcompress')) {

View File

@@ -11,6 +11,8 @@
namespace think\cache\driver;
use think\Cache;
/**
* 文件类型缓存类
* @author liu21st <liu21st@gmail.com>
@@ -96,7 +98,7 @@ class File
if (!is_file($filename)) {
return false;
}
\think\Cache::$readTimes++;
Cache::$readTimes++;
$content = file_get_contents($filename);
if (false !== $content) {
$expire = (int) substr($content, 8, 12);
@@ -127,7 +129,7 @@ class File
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -63,7 +64,7 @@ class Memcache
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
return $this->handler->get($this->options['prefix'] . $name);
}
@@ -77,7 +78,7 @@ class Memcache
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -62,7 +63,7 @@ class Redis
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
return $this->handler->get($this->options['prefix'] . $name);
}
@@ -76,7 +77,7 @@ class Redis
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -56,7 +57,7 @@ class Sae
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
return $this->handler->get($_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name);
}
@@ -70,7 +71,7 @@ class Sae
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,8 @@
namespace think\cache\driver;
use think\Cache;
/**
* Secache缓存驱动
* @author liu21st <liu21st@gmail.com>
@@ -53,7 +55,7 @@ class Secache
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$name = $this->options['prefix'] . $name;
$key = md5($name);
$this->handler->fetch($key, $return);
@@ -70,7 +72,7 @@ class Secache
*/
public function set($name, $value)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
$name = $this->options['prefix'] . $name;
$key = md5($name);
if ($result = $this->handler->store($key, $value)) {

View File

@@ -11,6 +11,8 @@
namespace think\cache\driver;
use think\Cache;
/**
* 文件类型缓存类
* @author liu21st <liu21st@gmail.com>
@@ -59,7 +61,7 @@ class Simple
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$filename = $this->filename($name);
if (is_file($filename)) {
return include $filename;
@@ -80,7 +82,7 @@ class Simple
*/
public function set($name, $value)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
$filename = $this->filename($name);
// 缓存数据
$dir = dirname($filename);

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -57,7 +58,7 @@ class Sqlite
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$name = $this->options['prefix'] . sqlite_escape_string($name);
$sql = 'SELECT value FROM ' . $this->options['table'] . ' WHERE var=\'' . $name . '\' AND (expire=0 OR expire >' . time() . ') LIMIT 1';
$result = sqlite_query($this->handler, $sql);
@@ -82,7 +83,7 @@ class Sqlite
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
$name = $this->options['prefix'] . sqlite_escape_string($name);
$value = sqlite_escape_string(serialize($value));
if (is_null($expire)) {

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -52,7 +53,7 @@ class Wincache
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$name = $this->options['prefix'] . $name;
return wincache_ucache_exists($name) ? wincache_ucache_get($name) : false;
}
@@ -67,7 +68,7 @@ class Wincache
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}

View File

@@ -11,6 +11,7 @@
namespace think\cache\driver;
use think\Cache;
use think\Exception;
/**
@@ -49,7 +50,7 @@ class Xcache
*/
public function get($name)
{
\think\Cache::$readTimes++;
Cache::$readTimes++;
$name = $this->options['prefix'] . $name;
if (xcache_isset($name)) {
return xcache_get($name);
@@ -67,7 +68,7 @@ class Xcache
*/
public function set($name, $value, $expire = null)
{
\think\Cache::$writeTimes++;
Cache::$writeTimes++;
if (is_null($expire)) {
$expire = $this->options['expire'];
}