Thinkphp 3.2.3中唯一能使redis动态缓存有效期生效的方法是先在每一个需要用到缓存的方法里创建缓存对象并指定有效期,然后在需要去除数据时先用get函数从redis里取值,如果有值,直接assign,如果返回为false,说明无值,从mysql里重新取值并用set方法存进redis数据库
//创建60秒缓存的缓存对象
$cache = S(array('expire'=>60));
$goodsinfo=$cache->get("Goods_showgoods_goodsinfo{$id}");
if(!$goodsinfo){
$goodsmodel = D("Goods");
$goodsinfo =$goodsmodel->where("id=$id and is_delete=0")->find();
$cache->set("Goods_showgoods_goodsinfo{$id}",$goodsinfo);}
$this->assign('goodsinfo',$goodsinfo);
转载于:https://my.oschina.net/u/2366466/blog/516800