瀏覽代碼

兑换商城首页加缓存10分钟过期

duqinya 5 年之前
父節點
當前提交
ae7a5e2032
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 8 0
      app/Repositories/CmsContentTemplateSetRepository.php
  2. 1 0
      config/constants.php

+ 8 - 0
app/Repositories/CmsContentTemplateSetRepository.php

@@ -192,6 +192,10 @@ class CmsContentTemplateSetRepository
         $group_array['apply_type'] = "exchangeMall";
         $group_array['title'] = $temalates->title;
         $group_array['content'] = [];
+        $exchange_key = config('constants.CMS_EXCHANGE');
+        if (Cache::has($exchange_key)) {
+            return Cache::store('redis')->get($exchange_key);
+        }
 
         $banner_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $temalates->id, 'area_type' => 0, 'status' => 1])->limit(1)->first();
         $new_rule = [];
@@ -261,6 +265,10 @@ class CmsContentTemplateSetRepository
             $group_array['content'][$count + $key + 1]['rule'] = $val['rule'];
         }
 
+        if (!Cache::has($exchange_key)) {
+            Cache::store('redis')->put($exchange_key, $group_array, 600);//10分钟过期
+        }
+
         return $group_array;
     }
 

+ 1 - 0
config/constants.php

@@ -7,4 +7,5 @@
 return [
     'CMS_GROUP' => env('REDIS_CMS_GROUP_KEY', 'cms_shop_group'),
     'CMS_MARKET' => env('REDIS_CMS_MARKET_KEY', 'cms_shop_market'),
+    'CMS_EXCHANGE' => env('REDIS_CMS_EXCHANGE_KEY', 'cms_shop_exchange'),
 ];