修改全局配置 phpGrace/config.php
'cache' => array( 'type' => 'file', 'pre' => 'grace_' //缓存变量前缀 )
演示示例
<?php
class indexController extends grace{
//根据缓存情况设置、读取缓存数据
public function index(){
$this->cache('test', 12, '__getData');
p($this->test);
}
public function __getData(){
echo '无缓存,进行查询...<br />';
$db = db('persons');
$persons = $db->fetchAll();
return $persons;
}
//删除指定的缓存
public function t(){
$this->removeCache('test', '12');
}
//清空缓存
public function t2(){
$this->clearCache();
}
}
说明:
缓存数据会保存为控制器的成员变量,规则 $this->缓存名称;