合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
## niushop缓存技术 niushop缓存采用thinkphp5的缓存技术实现,缓存包括数据缓存与请求缓存: 1、数据缓存:也就是thinkphp的cache缓存: cache("设置缓存变量", "缓存数据", "缓存时效"); 例如首页板块的缓存: cache("block_data_".$block_id, $info); //表示设置缓存 cache("block_data_".$block_id, null); //表示清除缓存 2、请求缓存:也就是thinkphp的请求缓存(具体参照thinkphp5手册) 请求缓存仅对GET请求有效,有两种方式可以设置请求缓存。 路由参数 可以在路由规则里面定义 cache 参数开启当前路由规则的请求缓存,例如: Route::get('new/:id','News/read',['cache'=>3600]); 系统请求缓存放在common.php公共函数调用: /** * 配置pc端缓存 */ function getShopCache(){ if(!Request::instance()->isAjax()) { $model = Request::instance()->module(); $model = strtolower($model); $controller = Request::instance()->controller(); $controller = strtolower($controller); $action = Request::instance()->action(); $action = strtolower($action); if($model =='shop' && $controller =='index' && $action="index" ) { if(Request::instance()->isMobile()) { Redirect::create("wap/index/index"); }else{ Request::instance()->cache('/web/document',1800); } } if($model == 'shop' && $controller !='goods' && $controller !='member' ) { Request::instance()->cache('/web/document',1800); } if($model == 'shop' && $controller =='goods' && $action =='brandlist' ) { Request::instance()->cache('/web/document',1800); } } } /** * 获取手机端缓存 */ function getWapCache(){ if(!Request::instance()->isAjax()) { $model = Request::instance()->module(); $model = strtolower($model); $controller = Request::instance()->controller(); $controller = strtolower($controller); $action = Request::instance()->action(); $action = strtolower($action); //店铺页面缓存8分钟 if($model == 'wap' && $controller =='shop' && $action =='index' ) { Request::instance()->cache('/web/document',480); } if($model == 'wap' && $controller !='goods' && $controller !='member' ) { Request::instance()->cache('/web/document',1800); } if($model == 'wap' && $controller =='goods' && $action !='brandlist' ) { Request::instance()->cache('/web/document',1800); } if($model == 'wap' && $controller =='goods' && $action !='goodsGroupList' ) { Request::instance()->cache('/web/document',1800); } } }