增加接口类 规范驱动扩展

This commit is contained in:
thinkphp
2016-05-05 07:39:05 +08:00
parent 3774e3451a
commit 7a8bb3b54f
33 changed files with 237 additions and 64 deletions

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Apc缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Apc
class Apc implements CacheInterface
{
protected $options = [

View 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();
}

View File

@@ -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'] . '`');
}
}
}

View File

@@ -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);
}

View File

@@ -17,7 +17,7 @@ use think\Cache;
* 文件类型缓存类
* @author liu21st <liu21st@gmail.com>
*/
class Lite
class Lite implements CacheInterface
{
protected $options = [
'prefix' => '',

View File

@@ -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 = [

View File

@@ -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 = [

View File

@@ -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 {

View File

@@ -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 = [

View File

@@ -17,7 +17,7 @@ use think\Cache;
* Secache缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Secache
class Secache implements CacheInterface
{
protected $handler = null;

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Sqlite缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Sqlite
class Sqlite implements CacheInterface
{
protected $options = [

View File

@@ -17,7 +17,7 @@ use think\Cache;
* 测试缓存类
* @author liu21st <liu21st@gmail.com>
*/
class Test
class Test implements CacheInterface
{
/**

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Wincache缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Wincache
class Wincache implements CacheInterface
{
protected $options = [

View File

@@ -18,7 +18,7 @@ use think\Exception;
* Xcache缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Xcache
class Xcache implements CacheInterface
{
protected $options = [