### 緩存
*****
如果要使用緩存功能,可以使用`\tian\Cache`類。
緩存數據文件位置在:runtime/cache/
**設置緩存**:
```
Cache::set("info", $info);
```
上面 info 是緩存名稱,$info 是數據源,數據源可以是字符串,數組,對象,Json等。
**獲取緩存**:
```
Cache::get("info");
```
**刪除緩存**:
```
Cache::del("info");
```
**驗證緩存是否存在**:
```
Cache::has("info");
```
has驗證緩存是否存在,返回為 true 或 false
**完整示例**:
```
<php
namespace app\home\controller;
use tian\Controller;
use tian\Cache;
use think\facade\Db;
class Base extends Controller
{
public $lm;
public function index()
{
//獲取導航欄目
if (Cache::has("lm")==false) {
$this->lm = $lm = Db::name('nav')->where('fid=0')->order('sort asc,id asc')->select()->toArray();
Cache::set("lm", $lm);
}else{
$this->lm = Cache::get("lm");
}
//數據賦值
$this->assign('lm',$this->lm);
//模板渲染
$this->fetch('index');
}
}
```