qeephp缓存

首先在app.yaml文件中定义一个变量来保存缓存内容:

#首页新增会员缓存
member_promo_prefix:
  member_promo_prefix

然后在控制器中编写缓存:

//取出最新注册会员
$member_cid = Q::ini('member_promo_prefix');
$member_backend = Q::ini('not_runtime_file_cache_backend');
$member_policy['life_time'] = 600;
//取出缓存中的数据		
$member_caches = Q::cache($member_cid, $member_policy, $member_backend);
		
if($member_caches === false)
{
    $member_caches = User::find()
		     ->order('dateline DESC')
		     ->where('activate_status = ? AND forbidden_status = ?', 1 , 0)
		     ->get(5);
if(!$member_caches)
    $member_caches = array();
    //将变量内容写入缓存,失败抛出异常          
    Q::writeCache($member_cid, $member_caches, $member_policy);
}
		
//dump($member_caches);exit();  //输出缓存中的数据

 渲染视图:

$this->_view['members'] = $member_caches;

 

你可能感兴趣的:(qeephp缓存)