qeephp缓存如何配置

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

  1. #首页新增会员缓存
  2. member_promo_prefix:
  3. member_promo_prefix

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

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

 渲染视图:

$this->_view[‘members’] =$member_caches;

THE END
喜欢就支持一下吧
点赞233 分享