cache.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * 清理缓存
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
  7. require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
  8. class cacheControl extends SystemControl
  9. {
  10. private $mPublisher;
  11. protected $cacheItems = array(
  12. 'setting', // 基本缓存
  13. 'seo', // SEO缓存
  14. 'groupbuy_price', // 抢购价格区间
  15. 'nav', // 底部导航缓存
  16. 'express', // 快递公司
  17. 'store_class', // 店铺分类
  18. 'store_grade', // 店铺等级
  19. 'store_msg_tpl', // 店铺消息
  20. 'member_msg_tpl', // 用户消息
  21. 'consult_type', // 咨询类型
  22. 'circle_level', // 圈子成员等级
  23. 'area', // 省市区地址
  24. 'home_goods', // 手机首页商品缓存
  25. 'android_version', // Andrid手机版本信息缓存
  26. );
  27. //'bonus', // 手机红包相关缓存
  28. //'specials', // 手机专题活动相关缓存
  29. //'discovery', // 手机发现页相关缓存
  30. // salelist //手机促销相关数据
  31. protected $cacher = '';
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. Language::read('cache');
  36. $this->cacher = Cache::getInstance('cacheredis');
  37. $this->mPublisher = new message\publisher();
  38. }
  39. /**
  40. * 清理缓存
  41. */
  42. public function clearOp()
  43. {
  44. if (!chksubmit()) {
  45. Tpl::showpage('cache.clear');
  46. return;
  47. }
  48. $lang = Language::getLangContent();
  49. // 清理所有缓存
  50. if ($_POST['cls_full'] == 1)
  51. {
  52. foreach ($this->cacheItems as $i) {
  53. dkcache($i);
  54. }
  55. //area
  56. dkcache('area_toplevelareas'); // 省级别缓存处理
  57. dkcache('area_cityprovince'); // 市级别缓存处理
  58. dcache('area','mb_');
  59. // 表主键
  60. Model::dropTablePkArrayCache();
  61. // 商品分类
  62. dkcache('gc_class');
  63. dkcache('all_categories');
  64. dkcache('goods_class_seo');
  65. dkcache('class_tag');
  66. // 广告
  67. Model('adv')->makeApAllCache();
  68. // 首页
  69. Model('web_config')->getWebHtml('index', 1);
  70. delCacheFile('index');
  71. // 删除商品相关数据
  72. $this->del_keys('goods*');
  73. $this->mPublisher->modify_goods();
  74. // 删除手机红包相关缓存
  75. $this->del_keys('bonus*');
  76. //删除手机专题活动相关缓存
  77. $this->del_keys('mb_special*');
  78. $this->mPublisher->modify_index_special();
  79. dkcache('web_code_123');
  80. $this->mPublisher->modify_index_tabs();
  81. //删除手机发现页相关缓存
  82. $this->del_keys('discovery*');
  83. //删除手机促销相关数据
  84. $this->mPublisher->modify_seracher_init();
  85. $this->del_keys('mb_brand');
  86. dcache('brandex','mb_');
  87. $this->mPublisher->modify_index_brands();
  88. $this->mPublisher->modify_activity();
  89. $this->mPublisher->modify_activity_optional_goods();
  90. $this->mPublisher->modify_activity_goods_sampler();
  91. $this->mPublisher->modify_activity_bargain_goods();
  92. }
  93. else
  94. {
  95. $todo = (array) $_POST['cache'];
  96. foreach ($this->cacheItems as $i) {
  97. if (in_array($i, $todo)) {
  98. dkcache($i);
  99. }
  100. }
  101. // 表主键
  102. if (in_array('table', $todo)) {
  103. Model::dropTablePkArrayCache();
  104. }
  105. // 商品分类
  106. if (in_array('goodsclass', $todo)) {
  107. dkcache('gc_class');
  108. dkcache('all_categories');
  109. dkcache('goods_class_seo');
  110. dkcache('class_tag');
  111. }
  112. // 广告
  113. if (in_array('adv', $todo)) {
  114. Model('adv')->makeApAllCache();
  115. }
  116. // 首页
  117. if (in_array('index', $todo)) {
  118. Model('web_config')->getWebHtml('index', 1);
  119. delCacheFile('index');
  120. }
  121. // 省市区地址
  122. if (in_array('area', $todo)) {
  123. dkcache('area');
  124. dkcache('area_toplevelareas'); // 省级别缓存处理
  125. dkcache('area_cityprovince'); // 市级别缓存处理
  126. dcache('area','mb_');
  127. }
  128. // 删除商品相关数据
  129. if (in_array('goods',$todo)) {
  130. $this->del_keys('goods*');
  131. $this->mPublisher->modify_goods();
  132. }
  133. // 删除手机红包相关缓存
  134. if (in_array('bonus',$todo)) {
  135. $this->del_keys('bonus*');
  136. }
  137. // 删除手机专题活动相关缓存
  138. if (in_array('specials',$todo)) {
  139. $this->del_keys('mb_special*');
  140. $this->mPublisher->modify_index_special();
  141. dkcache('web_code_123');
  142. $this->mPublisher->modify_index_tabs();
  143. }
  144. // 删除手机发现页相关缓存
  145. if (in_array('discovery',$todo)) {
  146. $this->del_keys('discovery*');
  147. }
  148. // 删除手机促销相关数据
  149. if (in_array('salelist',$todo)) {
  150. dcache('brand','mb_');
  151. dcache('brandex','mb_');
  152. $this->mPublisher->modify_index_brands();
  153. }
  154. if (in_array('searcher_goods',$todo)) { //搜索引擎重新加载数据
  155. $this->mPublisher->modify_seracher_init();
  156. }
  157. if(in_array('pay_fcode',$todo)) {
  158. $this->mPublisher->modify_index_payfcode();
  159. $this->mPublisher->modify_index_presentfcode();
  160. }
  161. if(in_array('optional_goods',$todo)) {
  162. $this->mPublisher->modify_activity_optional_goods();
  163. }
  164. if(in_array('goods_sampler',$todo)) {
  165. $this->mPublisher->modify_activity_goods_sampler();
  166. }
  167. if(in_array('bargain_goods',$todo)) {
  168. $this->mPublisher->modify_activity_bargain_goods();
  169. }
  170. }
  171. $this->log(L('cache_cls_operate'));
  172. showMessage($lang['cache_cls_ok']);
  173. }
  174. private function inc_version($name)
  175. {
  176. $version = rkcache($name);
  177. if(empty($version)) {
  178. $version = 1;
  179. } else {
  180. $version = intval($version) + 1;
  181. }
  182. wkcache($name, $version);
  183. }
  184. /**
  185. * 删除通配的keys
  186. * @param $key
  187. * @return bool
  188. */
  189. protected function del_keys($key)
  190. {
  191. $keys = $this->cacher->keys($key);
  192. if(!empty($keys) && is_array($keys)){
  193. foreach($keys as $key) {
  194. $this->cacher->del($key);
  195. }
  196. }
  197. return true;
  198. }
  199. }