mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
缓存驱动类调整
This commit is contained in:
7
library/think/cache/driver/Apc.php
vendored
7
library/think/cache/driver/Apc.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,7 +28,7 @@ class Apc
|
|||||||
];
|
];
|
||||||
/*****************************
|
/*****************************
|
||||||
需要支持apc_cli模式
|
需要支持apc_cli模式
|
||||||
******************************/
|
******************************/
|
||||||
/**
|
/**
|
||||||
* 架构函数
|
* 架构函数
|
||||||
*
|
*
|
||||||
@@ -54,7 +55,7 @@ class Apc
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
return apc_fetch($this->options['prefix'] . $name);
|
return apc_fetch($this->options['prefix'] . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ class Apc
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
6
library/think/cache/driver/Db.php
vendored
6
library/think/cache/driver/Db.php
vendored
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库方式缓存驱动
|
* 数据库方式缓存驱动
|
||||||
* CREATE TABLE think_cache (
|
* CREATE TABLE think_cache (
|
||||||
@@ -55,7 +57,7 @@ class Db
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$name = $this->options['prefix'] . addslashes($name);
|
$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');
|
$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) {
|
if (false !== $result) {
|
||||||
@@ -82,7 +84,7 @@ class Db
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
$data = serialize($value);
|
$data = serialize($value);
|
||||||
$name = $this->options['prefix'] . addslashes($name);
|
$name = $this->options['prefix'] . addslashes($name);
|
||||||
if (function_exists('gzcompress')) {
|
if (function_exists('gzcompress')) {
|
||||||
|
|||||||
6
library/think/cache/driver/File.php
vendored
6
library/think/cache/driver/File.php
vendored
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件类型缓存类
|
* 文件类型缓存类
|
||||||
* @author liu21st <liu21st@gmail.com>
|
* @author liu21st <liu21st@gmail.com>
|
||||||
@@ -96,7 +98,7 @@ class File
|
|||||||
if (!is_file($filename)) {
|
if (!is_file($filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$content = file_get_contents($filename);
|
$content = file_get_contents($filename);
|
||||||
if (false !== $content) {
|
if (false !== $content) {
|
||||||
$expire = (int) substr($content, 8, 12);
|
$expire = (int) substr($content, 8, 12);
|
||||||
@@ -127,7 +129,7 @@ class File
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
5
library/think/cache/driver/Memcache.php
vendored
5
library/think/cache/driver/Memcache.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +64,7 @@ class Memcache
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
return $this->handler->get($this->options['prefix'] . $name);
|
return $this->handler->get($this->options['prefix'] . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ class Memcache
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
5
library/think/cache/driver/Redis.php
vendored
5
library/think/cache/driver/Redis.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +63,7 @@ class Redis
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
return $this->handler->get($this->options['prefix'] . $name);
|
return $this->handler->get($this->options['prefix'] . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class Redis
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
5
library/think/cache/driver/Sae.php
vendored
5
library/think/cache/driver/Sae.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,7 +57,7 @@ class Sae
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
return $this->handler->get($_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name);
|
return $this->handler->get($_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ class Sae
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
6
library/think/cache/driver/Secache.php
vendored
6
library/think/cache/driver/Secache.php
vendored
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secache缓存驱动
|
* Secache缓存驱动
|
||||||
* @author liu21st <liu21st@gmail.com>
|
* @author liu21st <liu21st@gmail.com>
|
||||||
@@ -53,7 +55,7 @@ class Secache
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$name = $this->options['prefix'] . $name;
|
$name = $this->options['prefix'] . $name;
|
||||||
$key = md5($name);
|
$key = md5($name);
|
||||||
$this->handler->fetch($key, $return);
|
$this->handler->fetch($key, $return);
|
||||||
@@ -70,7 +72,7 @@ class Secache
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value)
|
public function set($name, $value)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
$name = $this->options['prefix'] . $name;
|
$name = $this->options['prefix'] . $name;
|
||||||
$key = md5($name);
|
$key = md5($name);
|
||||||
if ($result = $this->handler->store($key, $value)) {
|
if ($result = $this->handler->store($key, $value)) {
|
||||||
|
|||||||
6
library/think/cache/driver/Simple.php
vendored
6
library/think/cache/driver/Simple.php
vendored
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件类型缓存类
|
* 文件类型缓存类
|
||||||
* @author liu21st <liu21st@gmail.com>
|
* @author liu21st <liu21st@gmail.com>
|
||||||
@@ -59,7 +61,7 @@ class Simple
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$filename = $this->filename($name);
|
$filename = $this->filename($name);
|
||||||
if (is_file($filename)) {
|
if (is_file($filename)) {
|
||||||
return include $filename;
|
return include $filename;
|
||||||
@@ -80,7 +82,7 @@ class Simple
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value)
|
public function set($name, $value)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
$filename = $this->filename($name);
|
$filename = $this->filename($name);
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
$dir = dirname($filename);
|
$dir = dirname($filename);
|
||||||
|
|||||||
5
library/think/cache/driver/Sqlite.php
vendored
5
library/think/cache/driver/Sqlite.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +58,7 @@ class Sqlite
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$name = $this->options['prefix'] . sqlite_escape_string($name);
|
$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';
|
$sql = 'SELECT value FROM ' . $this->options['table'] . ' WHERE var=\'' . $name . '\' AND (expire=0 OR expire >' . time() . ') LIMIT 1';
|
||||||
$result = sqlite_query($this->handler, $sql);
|
$result = sqlite_query($this->handler, $sql);
|
||||||
@@ -82,7 +83,7 @@ class Sqlite
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
$name = $this->options['prefix'] . sqlite_escape_string($name);
|
$name = $this->options['prefix'] . sqlite_escape_string($name);
|
||||||
$value = sqlite_escape_string(serialize($value));
|
$value = sqlite_escape_string(serialize($value));
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
|
|||||||
5
library/think/cache/driver/Wincache.php
vendored
5
library/think/cache/driver/Wincache.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +53,7 @@ class Wincache
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$name = $this->options['prefix'] . $name;
|
$name = $this->options['prefix'] . $name;
|
||||||
return wincache_ucache_exists($name) ? wincache_ucache_get($name) : false;
|
return wincache_ucache_exists($name) ? wincache_ucache_get($name) : false;
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ class Wincache
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
5
library/think/cache/driver/Xcache.php
vendored
5
library/think/cache/driver/Xcache.php
vendored
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\cache\driver;
|
namespace think\cache\driver;
|
||||||
|
|
||||||
|
use think\Cache;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +50,7 @@ class Xcache
|
|||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
\think\Cache::$readTimes++;
|
Cache::$readTimes++;
|
||||||
$name = $this->options['prefix'] . $name;
|
$name = $this->options['prefix'] . $name;
|
||||||
if (xcache_isset($name)) {
|
if (xcache_isset($name)) {
|
||||||
return xcache_get($name);
|
return xcache_get($name);
|
||||||
@@ -67,7 +68,7 @@ class Xcache
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value, $expire = null)
|
public function set($name, $value, $expire = null)
|
||||||
{
|
{
|
||||||
\think\Cache::$writeTimes++;
|
Cache::$writeTimes++;
|
||||||
if (is_null($expire)) {
|
if (is_null($expire)) {
|
||||||
$expire = $this->options['expire'];
|
$expire = $this->options['expire'];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user