cache.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * 清理缓存
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class cacheControl extends SystemControl
  7. {
  8. protected $cacheItems = array(
  9. 'setting', // 基本缓存
  10. 'seo', // SEO缓存
  11. 'groupbuy_price', // 抢购价格区间
  12. 'nav', // 底部导航缓存
  13. 'express', // 快递公司
  14. 'store_class', // 店铺分类
  15. 'store_grade', // 店铺等级
  16. 'store_msg_tpl', // 店铺消息
  17. 'member_msg_tpl', // 用户消息
  18. 'consult_type', // 咨询类型
  19. 'circle_level', // 圈子成员等级
  20. 'area', // 省市区地址
  21. 'home_goods', // 手机首页商品缓存
  22. //'bonus', // 手机红包相关缓存
  23. //'specials', // 手机专题活动相关缓存
  24. //'discovery', // 手机发现页相关缓存
  25. );
  26. protected $cacher = '';
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. Language::read('cache');
  31. $this->cacher = Cache::getInstance('cacheredis');
  32. }
  33. /**
  34. * 清理缓存
  35. */
  36. public function clearOp()
  37. {
  38. if (!chksubmit()) {
  39. Tpl::showpage('cache.clear');
  40. return;
  41. }
  42. $lang = Language::getLangContent();
  43. // 清理所有缓存
  44. if ($_POST['cls_full'] == 1) {
  45. foreach ($this->cacheItems as $i) {
  46. dkcache($i);
  47. }
  48. //area
  49. dkcache('area_toplevelareas'); // 省级别缓存处理
  50. dkcache('area_cityprovince'); // 市级别缓存处理
  51. // 表主键
  52. Model::dropTablePkArrayCache();
  53. // 商品分类
  54. dkcache('gc_class');
  55. dkcache('all_categories');
  56. dkcache('goods_class_seo');
  57. dkcache('class_tag');
  58. // 广告
  59. Model('adv')->makeApAllCache();
  60. // 首页
  61. Model('web_config')->getWebHtml('index', 1);
  62. delCacheFile('index');
  63. // 删除商品相关数据
  64. $this->del_keys('goods*');
  65. // 删除手机红包相关缓存
  66. $this->del_keys('bonus*');
  67. //删除手机专题活动相关缓存
  68. $this->del_keys('specials*');
  69. //删除手机发现页相关缓存
  70. $this->del_keys('discovery*');
  71. } else {
  72. $todo = (array) $_POST['cache'];
  73. foreach ($this->cacheItems as $i) {
  74. if (in_array($i, $todo)) {
  75. dkcache($i);
  76. }
  77. }
  78. // 表主键
  79. if (in_array('table', $todo)) {
  80. Model::dropTablePkArrayCache();
  81. }
  82. // 商品分类
  83. if (in_array('goodsclass', $todo)) {
  84. dkcache('gc_class');
  85. dkcache('all_categories');
  86. dkcache('goods_class_seo');
  87. dkcache('class_tag');
  88. }
  89. // 广告
  90. if (in_array('adv', $todo)) {
  91. Model('adv')->makeApAllCache();
  92. }
  93. // 首页
  94. if (in_array('index', $todo)) {
  95. Model('web_config')->getWebHtml('index', 1);
  96. delCacheFile('index');
  97. }
  98. // 省市区地址
  99. if (in_array('area', $todo)) {
  100. dkcache('area');
  101. dkcache('area_toplevelareas'); // 省级别缓存处理
  102. dkcache('area_cityprovince'); // 市级别缓存处理
  103. }
  104. // 删除商品相关数据
  105. if (in_array('goods',$todo)) {
  106. $this->del_keys('goods*');
  107. }
  108. // 删除手机红包相关缓存
  109. if (in_array('bonus',$todo)) {
  110. $this->del_keys('bonus*');
  111. }
  112. // 删除手机专题活动相关缓存
  113. if (in_array('specials',$todo)) {
  114. $this->del_keys('specials*');
  115. }
  116. // 删除手机发现页相关缓存
  117. if (in_array('discovery',$todo)) {
  118. $this->del_keys('discovery*');
  119. }
  120. }
  121. $this->log(L('cache_cls_operate'));
  122. showMessage($lang['cache_cls_ok']);
  123. }
  124. /**
  125. * 删除通配的keys
  126. * @param $key
  127. * @return bool
  128. */
  129. protected function del_keys($key) {
  130. $keys = $this->cacher->keys($key);
  131. if(!empty($keys) && is_array($keys)){
  132. foreach($keys as $key) {
  133. $this->cacher->del($key);
  134. }
  135. }
  136. return true;
  137. }
  138. }