我这里不给大家说S方法,f方法之间的区别,晚上一大堆,我就直接写一些简单的例子:
S方法:
public function showlist(){
$goods = D('Goods');
$value = S('goods');
//dump($value);
if(empty($value)){
$arrgoods = $goods->cache(goods,120)->select();
//dump($arrgoods);
echo "数据库数据";
$this->assign('arr_goods',$arrgoods);
$this->display();
}else{
echo "缓存数据";
$this->assign('arr_goods',$value);
$this->display();
}
}
F方法:
public function showlist(){
$roles = D('Role');
//$role_list =S('roles');
$role_list =F('roles','',TEMP_PATH);
//dump($role_list);exit;
if(empty($role_list)){
$role_list = $roles->select();
//S('roles',$role_list,120);
F('roles',$role_list,TEMP_PATH);
echo "这是从数据库直接读取的数据";
$this->assign('roles',$role_list);
}else{
echo "这是缓存文件";
$this->assign('roles',$role_list);
}
$this->display();
}
实例化缓存类:
public function showlist(){
//dump(get_defined_constants(true));
$cate = D('brand');
//实例化缓存类:getInstance('缓存方式','缓存参数'),
$Cache = Cache::getInstance('File',array('expire'=>'60'));
$value = $Cache->getOptions('arr_brand');
//dump($value);
if(empty($value)){
$arr_brand = $cate ->order('addtime desc')->select();
$Cache->setOptions('arr_brand',$arr_brand);
echo "数据库数据";
$this->assign('brand',$arr_brand);
}else{
echo "缓存数据";
$this->assign('brand',$value);
}
$this->display();
}