瀏覽代碼

首页加缓存

duqinya 6 年之前
父節點
當前提交
06ab805dee

+ 14 - 0
app/Repositories/CmsContentTemplateRepository.php

@@ -5,6 +5,7 @@ namespace App\Repositories;
 
 use App\Models\CmsContentTemplate;
 use App\Models\CmsContentTemplateSet;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 use Symfony\Component\HttpKernel\Exception\HttpException;
 
@@ -73,6 +74,9 @@ class CmsContentTemplateRepository {
      */
     public function edit($request)
     {
+        $group_key = env('REDIS_HOME_GROUP_KEY');
+        $market_key = env('REDIS_HOME_MARKET_KEY');
+
         $template_id = $this->cmsContentTemplate->find($request['id']);
         if ($request['city_id'] == 610100 && $request['is_open'] == 0){
             throw new HttpException(500, '城市为西安的模板不允许手动关闭');
@@ -89,9 +93,19 @@ class CmsContentTemplateRepository {
         $template_id->updated_at = date('Y-m-d H:i:s');
 
         $res = $template_id->save();
+
         if (!$res) {
             throw new HttpException(500, '修改状态失败');
         }
+        if ($template_id->apply_type == 0){
+            if (Cache::has($group_key)) {
+                Cache::forget($group_key);
+            }
+        }elseif ($template_id->apply_type == 1){
+            if (Cache::has($market_key)) {
+                Cache::forget($market_key);
+            }
+        }
 
     }
 

+ 13 - 0
app/Repositories/CmsContentTemplateSetRepository.php

@@ -7,6 +7,7 @@ use Dingo\Api\Http\Response;
 use App\Models\CmsContentTemplate;
 use App\Models\CmsContentTemplateSet;
 use App\Models\CmsSubjectProduct;
+use Illuminate\Support\Facades\Cache;
 use Symfony\Component\HttpKernel\Exception\HttpException;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Database\QueryException;
@@ -294,6 +295,9 @@ class CmsContentTemplateSetRepository {
      */
     public function release($request)
     {
+        $group_key = env('REDIS_HOME_GROUP_KEY');
+        $market_key = env('REDIS_HOME_MARKET_KEY');
+
         //同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
         $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
         $where = [
@@ -349,6 +353,15 @@ class CmsContentTemplateSetRepository {
                 return Response::create();
             }
         }
+        if ($template->apply_type == 0){
+            if (Cache::has($group_key)) {
+                Cache::forget($group_key);
+            }
+        }elseif ($template->apply_type == 1){
+            if (Cache::has($market_key)) {
+                Cache::forget($market_key);
+            }
+        }
 
     }
 

+ 2 - 0
bootstrap/app.php

@@ -87,6 +87,8 @@ $app->register(App\Providers\AuthServiceProvider::class);
 
 $app->register(Dingo\Api\Provider\LumenServiceProvider::class);
 $app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
+$app->register(\Illuminate\Redis\RedisServiceProvider::class);
+
 /*
 |--------------------------------------------------------------------------
 | Load The Application Routes

+ 3 - 1
composer.json

@@ -13,7 +13,9 @@
         "laravel/lumen-framework": "5.8.*",
         "tymon/jwt-auth": "1.0.0-rc.4.1",
         "multilinguals/apollo-client": "^0.1.2",
-        "vlucas/phpdotenv": "^3.3"
+        "vlucas/phpdotenv": "^3.3",
+        "illuminate/redis": "^5.8",
+        "predis/predis": "^1.1"
     },
     "require-dev": {
         "fzaninotto/faker": "^1.4",