Thinkphp 3.2.3中使用redis动态缓存的注意点

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

相关文章
相关标签/搜索