mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
Cache类增加remember方法 用于当获取的缓存不存在的时候自动写入
This commit is contained in:
21
library/think/cache/Driver.php
vendored
21
library/think/cache/Driver.php
vendored
@@ -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
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user