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);
php