控制器使用-文件型

文件型缓存配置相对比较简单,将在本地生成缓存文件作为数据容器


设置缓存配置

配置文件位置:config/config.php

				
<?php
return [
	// 缓存设置
	'cache'             => [
		'type'          => 'file',//支持file, memcache, redis缓存类型
		'pre'           => 'ue_'// 缓存变量前缀
	]
];
				
			

演示示例

缓存数据会保存为控制器的成员变量,规则 $this->缓存名称;

				
<?php
class indexController extends Mb{
	
    //根据缓存情况设置、读取缓存数据
    public function index(){
        $this->cache('test', '__getData', 12);
        p($this->test);
    }
    
    public function __getData(){
        echo '无缓存,进行查询...<br />';
        $db = db('test');
        $test = $db->fetchAll();
        return $test;
    }
    
    //删除指定的缓存
    public function del(){
		$this->delCache('test','12');
    }
    
    //删除全部缓存
    public function delall(){
		$this->delCache('*');
    }
}