From ba85658c58a080d10778459bcb744ef1c37c0efe Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Sep 2016 22:08:55 +0800 Subject: [PATCH] =?UTF-8?q?request=E7=B1=BB=E8=AF=B7=E6=B1=82=E7=BC=93?= =?UTF-8?q?=E5=AD=98cache=E6=96=B9=E6=B3=95=E6=A0=87=E8=AF=86=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=98=E9=87=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 825d2a0f..c0ab36d2 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1456,15 +1456,23 @@ class Request } /** - * 读取缓存 + * 读取或者设置缓存 * @access public - * @param string $key 缓存标识 - * @param mixed $expire 静态有效期 + * @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id + * @param mixed $expire 缓存有效期 * @return mixed */ public function cache($key, $expire = null) { if (Cache::has($key)) { + if (false !== strpos($key, ':')) { + $param = $this->param(); + foreach ($param as $item => $val) { + if (is_string($val) && false !== strpos($key, ':' . $item)) { + $key = str_replace(':' . $item, $val, $key); + } + } + } // 读取缓存 $content = Cache::get($key); $response = Response::create($content)->header('Content-Type', Cache::get($key . '_header')); @@ -1474,6 +1482,11 @@ class Request } } + /** + * 读取缓存设置 + * @access public + * @return array + */ public function getCache() { return $this->cache;