123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- /**
- * 清理缓存
- ***/
- defined('InShopNC') or exit('Access Invalid!');
- require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
- require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
- class cacheControl extends SystemControl
- {
- private $mPublisher;
- protected $cacheItems = array(
- 'setting', // 基本缓存
- 'seo', // SEO缓存
- 'groupbuy_price', // 抢购价格区间
- 'nav', // 底部导航缓存
- 'express', // 快递公司
- 'store_class', // 店铺分类
- 'store_grade', // 店铺等级
- 'store_msg_tpl', // 店铺消息
- 'member_msg_tpl', // 用户消息
- 'consult_type', // 咨询类型
- 'circle_level', // 圈子成员等级
- 'area', // 省市区地址
- 'home_goods', // 手机首页商品缓存
- 'android_version', // Andrid手机版本信息缓存
- );
- //'bonus', // 手机红包相关缓存
- //'specials', // 手机专题活动相关缓存
- //'discovery', // 手机发现页相关缓存
- // salelist //手机促销相关数据
- protected $cacher = '';
- public function __construct()
- {
- parent::__construct();
- Language::read('cache');
- $this->cacher = Cache::getInstance('cacheredis');
- $this->mPublisher = new message\publisher();
- }
- /**
- * 清理缓存
- */
- public function clearOp()
- {
- if (!chksubmit()) {
- Tpl::showpage('cache.clear');
- return;
- }
- $lang = Language::getLangContent();
- // 清理所有缓存
- if ($_POST['cls_full'] == 1)
- {
- foreach ($this->cacheItems as $i) {
- dkcache($i);
- }
- //area
- dkcache('area_toplevelareas'); // 省级别缓存处理
- dkcache('area_cityprovince'); // 市级别缓存处理
- dcache('area','mb_');
- // 表主键
- Model::dropTablePkArrayCache();
- // 商品分类
- dkcache('gc_class');
- dkcache('all_categories');
- dkcache('goods_class_seo');
- dkcache('class_tag');
- // 广告
- Model('adv')->makeApAllCache();
- // 首页
- Model('web_config')->getWebHtml('index', 1);
- delCacheFile('index');
- // 删除商品相关数据
- $this->del_keys('goods*');
- $this->mPublisher->modify_goods();
- // 删除手机红包相关缓存
- $this->del_keys('bonus*');
- //删除手机专题活动相关缓存
- $this->del_keys('mb_special*');
- $this->mPublisher->modify_index_special();
- dkcache('web_code_123');
- $this->mPublisher->modify_index_tabs();
- //删除手机发现页相关缓存
- $this->del_keys('discovery*');
- //删除手机促销相关数据
- $this->mPublisher->modify_seracher_init();
- $this->del_keys('mb_brand');
- dcache('brandex','mb_');
- $this->mPublisher->modify_index_brands();
- $this->mPublisher->modify_activity();
- $this->mPublisher->modify_activity_optional_goods();
- $this->mPublisher->modify_activity_goods_sampler();
- $this->mPublisher->modify_activity_bargain_goods();
- }
- else
- {
- $todo = (array) $_POST['cache'];
- foreach ($this->cacheItems as $i) {
- if (in_array($i, $todo)) {
- dkcache($i);
- }
- }
- // 表主键
- if (in_array('table', $todo)) {
- Model::dropTablePkArrayCache();
- }
- // 商品分类
- if (in_array('goodsclass', $todo)) {
- dkcache('gc_class');
- dkcache('all_categories');
- dkcache('goods_class_seo');
- dkcache('class_tag');
- }
- // 广告
- if (in_array('adv', $todo)) {
- Model('adv')->makeApAllCache();
- }
- // 首页
- if (in_array('index', $todo)) {
- Model('web_config')->getWebHtml('index', 1);
- delCacheFile('index');
- }
- // 省市区地址
- if (in_array('area', $todo)) {
- dkcache('area');
- dkcache('area_toplevelareas'); // 省级别缓存处理
- dkcache('area_cityprovince'); // 市级别缓存处理
- dcache('area','mb_');
- }
- // 删除商品相关数据
- if (in_array('goods',$todo)) {
- $this->del_keys('goods*');
- $this->mPublisher->modify_goods();
- }
- // 删除手机红包相关缓存
- if (in_array('bonus',$todo)) {
- $this->del_keys('bonus*');
- }
- // 删除手机专题活动相关缓存
- if (in_array('specials',$todo)) {
- $this->del_keys('mb_special*');
- $this->mPublisher->modify_index_special();
- dkcache('web_code_123');
- $this->mPublisher->modify_index_tabs();
- }
- // 删除手机发现页相关缓存
- if (in_array('discovery',$todo)) {
- $this->del_keys('discovery*');
- }
- // 删除手机促销相关数据
- if (in_array('salelist',$todo)) {
- dcache('brand','mb_');
- dcache('brandex','mb_');
- $this->mPublisher->modify_index_brands();
- }
- if (in_array('searcher_goods',$todo)) { //搜索引擎重新加载数据
- $this->mPublisher->modify_seracher_init();
- }
- if(in_array('pay_fcode',$todo)) {
- $this->mPublisher->modify_index_payfcode();
- $this->mPublisher->modify_index_presentfcode();
- }
- if(in_array('optional_goods',$todo)) {
- $this->mPublisher->modify_activity_optional_goods();
- }
- if(in_array('goods_sampler',$todo)) {
- $this->mPublisher->modify_activity_goods_sampler();
- }
- if(in_array('bargain_goods',$todo)) {
- $this->mPublisher->modify_activity_bargain_goods();
- }
- }
- $this->log(L('cache_cls_operate'));
- showMessage($lang['cache_cls_ok']);
- }
- private function inc_version($name)
- {
- $version = rkcache($name);
- if(empty($version)) {
- $version = 1;
- } else {
- $version = intval($version) + 1;
- }
- wkcache($name, $version);
- }
- /**
- * 删除通配的keys
- * @param $key
- * @return bool
- */
- protected function del_keys($key)
- {
- $keys = $this->cacher->keys($key);
- if(!empty($keys) && is_array($keys)){
- foreach($keys as $key) {
- $this->cacher->del($key);
- }
- }
- return true;
- }
- }
|