增加请求缓存功能 路由支持设置请求缓存

This commit is contained in:
thinkphp
2016-09-24 18:14:59 +08:00
parent 13b345c889
commit 450d7ab313
3 changed files with 43 additions and 2 deletions

View File

@@ -119,6 +119,8 @@ class Request
protected $bind = [];
// php://input
protected $input;
// 请求缓存
protected $cache;
/**
* 架构函数
@@ -1453,6 +1455,30 @@ class Request
return $token;
}
/**
* 读取缓存
* @access public
* @param string $key 缓存标识
* @param mixed $expire 静态有效期
* @return mixed
*/
public function cache($key, $expire = null)
{
if (Cache::has($key)) {
// 读取缓存
$content = Cache::get($key);
$response = Response::create($content)->header('Content-Type', Cache::get($key . '_header'));
throw new \think\exception\HttpResponseException($response);
} else {
$this->cache = [$key, $expire];
}
}
public function getCache()
{
return $this->cache;
}
/**
* 设置当前请求绑定的对象实例
* @access public