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