mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
增加接口类 规范驱动扩展
This commit is contained in:
2
library/think/cache/driver/Apc.php
vendored
2
library/think/cache/driver/Apc.php
vendored
@@ -18,7 +18,7 @@ use think\Exception;
|
||||
* Apc缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Apc
|
||||
class Apc implements CacheInterface
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
|
||||
50
library/think/cache/driver/CacheInterface.php
vendored
Normal file
50
library/think/cache/driver/CacheInterface.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\cache\driver;
|
||||
|
||||
interface CacheInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* 读取缓存
|
||||
* @access public
|
||||
* @param string $name 缓存变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name);
|
||||
|
||||
/**
|
||||
* 写入缓存
|
||||
* @access public
|
||||
* @param string $name 缓存变量名
|
||||
* @param mixed $value 存储数据
|
||||
* @param int $expire 有效时间 0为永久
|
||||
* @return boolean
|
||||
*/
|
||||
public function set($name, $value, $expire = null);
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @access public
|
||||
* @param string $name 缓存变量名
|
||||
* @return boolean
|
||||
*/
|
||||
public function rm($name);
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear();
|
||||
|
||||
}
|
||||
28
library/think/cache/driver/Db.php
vendored
28
library/think/cache/driver/Db.php
vendored
@@ -24,23 +24,23 @@ use think\Cache;
|
||||
* );
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Db
|
||||
class Db implements CacheInterface
|
||||
{
|
||||
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
'type' => '',
|
||||
'dsn' => '',
|
||||
'hostname' => '',
|
||||
'hostport' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
'charset' => '',
|
||||
'table' => '',
|
||||
'prefix' => '',
|
||||
'expire' => 0,
|
||||
'length' => 0,
|
||||
'type' => '',
|
||||
'dsn' => '',
|
||||
'hostname' => '',
|
||||
'hostport' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
'charset' => '',
|
||||
'table' => '',
|
||||
'prefix' => '',
|
||||
'expire' => 0,
|
||||
'length' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -162,4 +162,4 @@ class Db
|
||||
return $this->handler->execute('TRUNCATE TABLE `' . $this->options['table'] . '`');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
4
library/think/cache/driver/File.php
vendored
4
library/think/cache/driver/File.php
vendored
@@ -17,7 +17,7 @@ use think\Cache;
|
||||
* 文件类型缓存类
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class File
|
||||
class File implements CacheInterface
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
@@ -186,7 +186,7 @@ class File
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$fileLsit = (array)glob($this->options['path'].'*');
|
||||
$fileLsit = (array) glob($this->options['path'] . '*');
|
||||
foreach ($fileLsit as $path) {
|
||||
is_file($path) && unlink($path);
|
||||
}
|
||||
|
||||
2
library/think/cache/driver/Lite.php
vendored
2
library/think/cache/driver/Lite.php
vendored
@@ -17,7 +17,7 @@ use think\Cache;
|
||||
* 文件类型缓存类
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Lite
|
||||
class Lite implements CacheInterface
|
||||
{
|
||||
protected $options = [
|
||||
'prefix' => '',
|
||||
|
||||
2
library/think/cache/driver/Memcache.php
vendored
2
library/think/cache/driver/Memcache.php
vendored
@@ -14,7 +14,7 @@ namespace think\cache\driver;
|
||||
use think\Cache;
|
||||
use think\Exception;
|
||||
|
||||
class Memcache
|
||||
class Memcache implements CacheInterface
|
||||
{
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
|
||||
2
library/think/cache/driver/Memcached.php
vendored
2
library/think/cache/driver/Memcached.php
vendored
@@ -14,7 +14,7 @@ namespace think\cache\driver;
|
||||
use think\Cache;
|
||||
use think\Exception;
|
||||
|
||||
class Memcached
|
||||
class Memcached implements CacheInterface
|
||||
{
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
|
||||
10
library/think/cache/driver/Redis.php
vendored
10
library/think/cache/driver/Redis.php
vendored
@@ -19,7 +19,7 @@ use think\Exception;
|
||||
* 要求安装phpredis扩展:https://github.com/nicolasff/phpredis
|
||||
* @author 尘缘 <130775@qq.com>
|
||||
*/
|
||||
class Redis
|
||||
class Redis implements CacheInterface
|
||||
{
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
@@ -65,10 +65,10 @@ class Redis
|
||||
public function get($name)
|
||||
{
|
||||
Cache::$readTimes++;
|
||||
$value = $this->handler->get($this->options['prefix'] . $name);
|
||||
$jsonData = json_decode( $value, true );
|
||||
$value = $this->handler->get($this->options['prefix'] . $name);
|
||||
$jsonData = json_decode($value, true);
|
||||
// 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson<xiaobo.sun@qq.com>
|
||||
return ($jsonData === null) ? $value : $jsonData;
|
||||
return (null === $jsonData) ? $value : $jsonData;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ class Redis
|
||||
}
|
||||
$name = $this->options['prefix'] . $name;
|
||||
//对数组/对象数据进行缓存处理,保证数据完整性 byron sampson<xiaobo.sun@qq.com>
|
||||
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
|
||||
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
|
||||
if (is_int($expire)) {
|
||||
$result = $this->handler->setex($name, $expire, $value);
|
||||
} else {
|
||||
|
||||
2
library/think/cache/driver/Sae.php
vendored
2
library/think/cache/driver/Sae.php
vendored
@@ -18,7 +18,7 @@ use think\Exception;
|
||||
* SAE Memcache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Sae
|
||||
class Sae implements CacheInterface
|
||||
{
|
||||
protected $handler = null;
|
||||
protected $options = [
|
||||
|
||||
2
library/think/cache/driver/Secache.php
vendored
2
library/think/cache/driver/Secache.php
vendored
@@ -17,7 +17,7 @@ use think\Cache;
|
||||
* Secache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Secache
|
||||
class Secache implements CacheInterface
|
||||
{
|
||||
|
||||
protected $handler = null;
|
||||
|
||||
2
library/think/cache/driver/Sqlite.php
vendored
2
library/think/cache/driver/Sqlite.php
vendored
@@ -18,7 +18,7 @@ use think\Exception;
|
||||
* Sqlite缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Sqlite
|
||||
class Sqlite implements CacheInterface
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
|
||||
2
library/think/cache/driver/Test.php
vendored
2
library/think/cache/driver/Test.php
vendored
@@ -17,7 +17,7 @@ use think\Cache;
|
||||
* 测试缓存类
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Test
|
||||
class Test implements CacheInterface
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
2
library/think/cache/driver/Wincache.php
vendored
2
library/think/cache/driver/Wincache.php
vendored
@@ -18,7 +18,7 @@ use think\Exception;
|
||||
* Wincache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Wincache
|
||||
class Wincache implements CacheInterface
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
|
||||
2
library/think/cache/driver/Xcache.php
vendored
2
library/think/cache/driver/Xcache.php
vendored
@@ -18,7 +18,7 @@ use think\Exception;
|
||||
* Xcache缓存驱动
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Xcache
|
||||
class Xcache implements CacheInterface
|
||||
{
|
||||
|
||||
protected $options = [
|
||||
|
||||
Reference in New Issue
Block a user