## 模块缓存
- 缓存是应用比较广泛的,可以使用TPHP内置的缓存。
设置文件/html/www/demo/test/cache/_init.php内容如下
~~~
<?php
return function (){
$test_cache = $this->cache(function (){
// 第一次执行
dump("You Come Here !");
return "Hello Tphp !";
});
// 清除上面缓存
// $this->unCache(); //或$this->unCache("")
dump($test_cache);
// "username" 和 300秒 可选,默认60 * 60 = 360秒
$test_cache = $this->cache(function (){
// 第一次执行
dump("My Name !");
return "OK !";
}, "username", 300);
// 清除上面缓存
// $this->unCache("username");
dump($test_cache);
// 指向上一路径
dump($this->getCacheid("../"));
// 指向当前路径下的tphp路径
dump($this->getCacheid("tphp"));
// 指向上一路径下的tphp路径
dump($this->getCacheid("../tphp"));
};
~~~
打开网址[http://demo.tphp.com/test/cache](http://demo.tphp.com/test/cache)获得如下效果
第一次打开

第二次打开
