改进Request类cache方法

This commit is contained in:
thinkphp
2016-09-27 18:33:29 +08:00
parent e8290be253
commit 6278cf13e9
2 changed files with 21 additions and 19 deletions

View File

@@ -1476,6 +1476,7 @@ class Request
*/ */
public function cache($key, $expire = null) public function cache($key, $expire = null)
{ {
if ($this->isGet()) {
if (false !== strpos($key, ':')) { if (false !== strpos($key, ':')) {
$param = $this->param(); $param = $this->param();
foreach ($param as $item => $val) { foreach ($param as $item => $val) {
@@ -1498,6 +1499,7 @@ class Request
$this->cache = [$key, $expire]; $this->cache = [$key, $expire];
} }
} }
}
/** /**
* 读取缓存设置 * 读取缓存设置

View File

@@ -115,7 +115,7 @@ class Response
if (200 == $this->code) { if (200 == $this->code) {
$cache = Request::instance()->getCache(); $cache = Request::instance()->getCache();
if ($cache && Request::instance()->isGet()) { if ($cache) {
Cache::set($cache[0], $data, $cache[1]); Cache::set($cache[0], $data, $cache[1]);
Cache::set($cache[0] . '_header', $this->header['Content-Type']); Cache::set($cache[0] . '_header', $this->header['Content-Type']);
} }