From cb9b2b5803370bdbfbfe1c0b27f85f8f41113dcd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 18 Oct 2016 16:19:06 +0800 Subject: [PATCH] =?UTF-8?q?Cache=E7=B1=BB=E5=A2=9E=E5=8A=A0remember?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E=E5=BD=93=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E7=BC=93=E5=AD=98=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/Driver.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index e0aeb7bc..a2a57795 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -109,6 +109,27 @@ abstract class Driver } } + /** + * 如果不存在则写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param int $expire 有效时间 0为永久 + * @return mixed + */ + public function remember($name, $value, $expire = null) + { + if (!$this->has($name)) { + if ($value instanceof \Closure) { + $value = call_user_func($value); + } + $this->set($name, $value, $expire); + } else { + $value = $this->get($name); + } + return $value; + } + /** * 缓存标签 * @access public