PSR规范调整

This commit is contained in:
thinkphp
2015-10-04 13:05:15 +08:00
parent 1cfb3704c6
commit 27e724bb3c
135 changed files with 9426 additions and 11556 deletions

View File

@@ -10,18 +10,20 @@
// +----------------------------------------------------------------------
namespace think\cache\driver;
use think\Exception;
/**
* Apc缓存驱动
* @author liu21st <liu21st@gmail.com>
*/
class Apc {
class Apc
{
protected $options = [
'expire' => 0,
'prefix' => '',
'length' => 0,
protected $options = [
'expire' => 0,
'prefix' => '',
'length' => 0,
];
/**
@@ -29,12 +31,13 @@ class Apc {
* @param array $options 缓存参数
* @access public
*/
public function __construct($options=[]) {
if(!function_exists('apc_cache_info')) {
public function __construct($options = [])
{
if (!function_exists('apc_cache_info')) {
throw new Exception('_NOT_SUPPERT_:Apc');
}
if(!empty($options)) {
$this->options = array_merge($this->options,$options);
if (!empty($options)) {
$this->options = array_merge($this->options, $options);
}
}
@@ -44,9 +47,10 @@ class Apc {
* @param string $name 缓存变量名
* @return mixed
*/
public function get($name) {
return apc_fetch($this->options['prefix'].$name);
}
public function get($name)
{
return apc_fetch($this->options['prefix'] . $name);
}
/**
* 写入缓存
@@ -56,22 +60,26 @@ class Apc {
* @param integer $expire 有效时间(秒)
* @return boolen
*/
public function set($name, $value, $expire = null) {
if(is_null($expire)) {
$expire = $this->options['expire'];
public function set($name, $value, $expire = null)
{
if (is_null($expire)) {
$expire = $this->options['expire'];
}
$name = $this->options['prefix'].$name;
if($result = apc_store($name, $value, $expire)) {
if($this->options['length']>0) {
$name = $this->options['prefix'] . $name;
if ($result = apc_store($name, $value, $expire)) {
if ($this->options['length'] > 0) {
// 记录缓存队列
$queue = apc_fetch('__info__');
if(!$queue) {
$queue = [];
$queue = apc_fetch('__info__');
if (!$queue) {
$queue = [];
}
if(false===array_search($name, $queue)) array_push($queue,$name);
if(count($queue) > $this->options['length']) {
if (false === array_search($name, $queue)) {
array_push($queue, $name);
}
if (count($queue) > $this->options['length']) {
// 出列
$key = array_shift($queue);
$key = array_shift($queue);
// 删除缓存
apc_delete($key);
}
@@ -79,7 +87,7 @@ class Apc {
}
}
return $result;
}
}
/**
* 删除缓存
@@ -87,16 +95,18 @@ class Apc {
* @param string $name 缓存变量名
* @return boolen
*/
public function rm($name) {
return apc_delete($this->options['prefix'].$name);
}
public function rm($name)
{
return apc_delete($this->options['prefix'] . $name);
}
/**
* 清除缓存
* @access public
* @return boolen
*/
public function clear() {
public function clear()
{
return apc_clear_cache();
}
}