Browse Source

use RedisClusters replace Cache

visuddhinanda 2 years ago
parent
commit
f25a985077

+ 1 - 1
app/Http/Api/TemplateRender.php

@@ -402,7 +402,7 @@ class TemplateRender{
     private  function render_quote(){
         $paraId = $this->get_param($this->param,"para",1);
         $channelId = $this->channel_id[0];
-        $props = Cache::remember("/quote/{$channelId}/{$paraId}",
+        $props = RedisClusters::remember("/quote/{$channelId}/{$paraId}",
               config('cache.expire',3600*24),
               function() use($paraId,$channelId){
                 $para = \explode('-',$paraId);

+ 4 - 4
app/Http/Controllers/CorpusController.php

@@ -664,7 +664,7 @@ class CorpusController extends Controller
 
                             break;
                         case 'nissaya':
-                            $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
+                            $newSent['html'] = RedisClusters::remember("/sent/{$channelId}/{$currSentId}",
                                                 config('cache.expire',3600*24),
                                                 function() use($row,$mode){
                                                     return MdRender::render($row->content,[$row->channel_uid],null,$mode,"nissaya",$row->content_type);
@@ -676,7 +676,7 @@ class CorpusController extends Controller
                          * 包涵术语的不用cache
                          */
                             if(strpos($row->content,'[[')===false){
-                                $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
+                                $newSent['html'] = RedisClusters::remember("/sent/{$channelId}/{$currSentId}",
                                                     config('cache.expire',3600*24),
                                                 function() use($row){
                                                     return MdRender::render($row->content,[$row->channel_uid]);
@@ -914,7 +914,7 @@ class CorpusController extends Controller
         }else{
             $key .= 'guest';
         }
-		$channelCount = Cache::remember($key,config('cache.expire',3600*24),
+		$channelCount = RedisClusters::remember($key,config('cache.expire',3600*24),
                           function() use($book,$para,$start,$end,$userUuid){
                             $keyCanRead="/channel/can-read/";
                             if($userUuid){
@@ -922,7 +922,7 @@ class CorpusController extends Controller
                             }else{
                                 $keyCanRead .= 'guest';
                             }
-                            $channelCanRead = Cache::remember($keyCanRead,
+                            $channelCanRead = RedisClusters::remember($keyCanRead,
                                                 config('cache.expire',3600*24),
                                                 function() use($userUuid){
                                                     return ChannelApi::getCanReadByUser($userUuid);

+ 5 - 5
app/Http/Controllers/DhammaTermController.php

@@ -135,7 +135,7 @@ class DhammaTermController extends Controller
 				break;
             case 'hot-meaning':
                 $key='term/hot_meaning';
-                $value = Cache::get($key, function()use($request) {
+                $value = RedisClusters::get($key, function()use($request) {
                     $hotMeaning=[];
                     $words = DhammaTerm::select('word')
                                 ->where('language',$request->get("language"))
@@ -159,7 +159,7 @@ class DhammaTermController extends Controller
                             ];
                         }
                     }
-                    Cache::put($key, $hotMeaning, 3600);
+                    RedisClusters::put($key, $hotMeaning, 3600);
                     return $hotMeaning;
                 }, config('cache.expire',3600*24));
                 return $this->ok(["rows"=>$value,"count"=>count($value)]);
@@ -274,10 +274,10 @@ class DhammaTermController extends Controller
             //通用 查询studio所有channel
             $channels = Channel::where('owner_uid',$term->owner)->select('uid')->get();
             foreach ($channels as $channel) {
-                Cache::forget("/term/{$channel}/{$term->word}");
+                RedisClusters::forget("/term/{$channel}/{$term->word}");
             }
         }else{
-            Cache::forget("/term/{$term->channal}/{$term->word}");
+            RedisClusters::forget("/term/{$term->channal}/{$term->word}");
         }
     }
 
@@ -449,7 +449,7 @@ class DhammaTermController extends Controller
         $fId = Str::uuid();
         $filename = storage_path("app/tmp/{$fId}");
         $writer->save($filename);
-        Cache::put("download/tmp/{$fId}",file_get_contents($filename),300);
+        RedisClusters::put("download/tmp/{$fId}",file_get_contents($filename),300);
         unlink($filename);
         return $this->ok(['uuid'=>$fId,'filename'=>"term.xlsx",'type'=>"application/vnd.ms-excel"]);
     }

+ 1 - 1
app/Http/Controllers/DictMeaningController.php

@@ -50,7 +50,7 @@ class DictMeaningController extends Controller
             foreach ($this->langOrder[$lang] as $key => $value) {
                 # 遍历每种语言。找到返回
                 $cacheKey = "dict_first_mean/{$value}/{$word}";
-                $meaning = Cache::get($cacheKey);
+                $meaning = RedisClusters::get($cacheKey);
                 if(!empty($meaning)){
                     $currMeaning = $meaning;
                     break;

+ 1 - 1
app/Http/Controllers/PaliTextController.php

@@ -206,7 +206,7 @@ class PaliTextController extends Controller
                     if(is_object($value)){
                         //TODO $value->book 可能不存在
                         $progress_key="/chapter_dynamic/{$value->book}/{$value->paragraph}/global";
-                        $chapters[$key]->progress_line = Cache::get($progress_key);
+                        $chapters[$key]->progress_line = RedisClusters::get($progress_key);
                     }
                 }
             }

+ 1 - 1
app/Http/Controllers/ProgressChapterController.php

@@ -230,7 +230,7 @@ class ProgressChapterController extends Controller
                     $chapters[$key]->studio = StudioApi::getById($value->owner_uid);
                     $chapters[$key]->channel = ['uid'=>$value->channel_id,'name'=>$value->name,'type'=>$value->type];
                     $progress_key="/chapter_dynamic/{$value->book}/{$value->para}/ch_{$value->channel_id}";
-                    $chapters[$key]->progress_line = Cache::get($progress_key);
+                    $chapters[$key]->progress_line = RedisClusters::get($progress_key);
                 }
 
                 $all_count = count($chapters);

+ 2 - 2
app/Http/Controllers/ProgressImgController.php

@@ -41,10 +41,10 @@ class ProgressImgController extends Controller
         //
         return response()->stream(function () use ($id) {
             $key = str_replace('-','/',$id);
-            $svg = Cache::get('svg/'.$key, function () use ($key) {
+            $svg = RedisClusters::get('svg/'.$key, function () use ($key) {
                 $viewHeight = 60;
                 $svg = "<svg xmlns='http://www.w3.org/2000/svg'  fill='currentColor' viewBox='0 0 300 60'>";
-                $data = Cache::get($key);
+                $data = RedisClusters::get($key);
                 if(is_array($data)){
                     $point = [];
                     foreach ($data as $key => $value) {

+ 4 - 4
app/Http/Controllers/RelationController.php

@@ -24,8 +24,8 @@ class RelationController extends Controller
         //
         $key = 'relation-vocabulary';
         if($request->has('vocabulary')){
-            if(Cache::has($key)){
-                return $this->ok(Cache::get($key));
+            if(RedisClusters::has($key)){
+                return $this->ok(RedisClusters::get($key));
             }
         }
         $table = Relation::select(['id','name','case','from','to',
@@ -62,8 +62,8 @@ class RelationController extends Controller
         $output = ["rows"=>RelationResource::collection($result),"count"=>$count];
 
         if($request->has('vocabulary')){
-            if(!Cache::has($key)){
-                Cache::put($key,$output,config('cache.expire',3600*24));
+            if(!RedisClusters::has($key)){
+                RedisClusters::put($key,$output,config('cache.expire',3600*24));
             }
         }
         return $this->ok($output);

+ 1 - 1
app/Http/Controllers/SentenceController.php

@@ -382,7 +382,7 @@ class SentenceController extends Controller
         //清除cache
         $channelId = $param[4];
         $currSentId = "{$param[0]}-{$param[1]}-{$param[2]}-{$param[3]}";
-        Cache::forget("/sent/{$channelId}/{$currSentId}");
+        RedisClusters::forget("/sent/{$channelId}/{$currSentId}");
         //保存历史记录
         $this->saveHistory($sent->uid,$user["user_uid"],$request->get('content'));
         Mq::publish('progress',['book'=>$param[0],

+ 1 - 1
app/Http/Controllers/SentenceInfoController.php

@@ -129,7 +129,7 @@ class SentenceInfoController extends Controller
             foreach ($sentFinished as $sent) {
                 # code...
 				$key_sent_id = $sent->book_id.'-'.$sent->paragraph.'-'.$sent->word_start.'-'.$sent->word_end;
-				$para_strlen += Cache::remember('pali-sent/strlen/'.$key_sent_id,
+				$para_strlen += RedisClusters::remember('pali-sent/strlen/'.$key_sent_id,
                                     config('cache.expire',3600*24*30) ,
                                     function() use($sent) {
                                         return PaliSentence::where('book',$sent->book_id)

+ 8 - 8
app/Http/Controllers/UserStatisticController.php

@@ -60,45 +60,45 @@ class UserStatisticController extends Controller
         $queryUserUuid = UserApi::getIdByName($userName);
         $cacheExpiry = config('cache.expire',3600*24);
         //总经验值
-        $expSum = Cache::remember("user/{$userName}/exp/sum",$cacheExpiry,function() use($queryUserId){
+        $expSum = RedisClusters::remember("user/{$userName}/exp/sum",$cacheExpiry,function() use($queryUserId){
 			return UserOperationDaily::where('user_id',$queryUserId)
                                      ->sum('duration');
 		});
 
         //逐词解析
-        $wbwCount = Cache::remember("user/{$userName}/wbw/count",$cacheExpiry,function() use($queryUserId){
+        $wbwCount = RedisClusters::remember("user/{$userName}/wbw/count",$cacheExpiry,function() use($queryUserId){
                     return Wbw::where('editor_id',$queryUserId)
                         ->count();
                         });
         //查字典次数
-        $lookupCount = Cache::remember("user/{$userName}/lookup/count",$cacheExpiry,function() use($queryUserId){
+        $lookupCount = RedisClusters::remember("user/{$userName}/lookup/count",$cacheExpiry,function() use($queryUserId){
                             return UserOperationLog::where('user_id',$queryUserId)
                                                     ->where('op_type','dict_lookup')
                                                     ->count();
                                 });
         //译文
         //TODO 判断是否是译文channel
-        $translationCount = Cache::remember("user/{$userName}/translation/count",$cacheExpiry,function() use($queryUserUuid){
+        $translationCount = RedisClusters::remember("user/{$userName}/translation/count",$cacheExpiry,function() use($queryUserUuid){
                             return Sentence::where('editor_uid',$queryUserUuid)
                                            ->count();
                             });
-        $translationCountPub = Cache::remember("user/{$userName}/translation/count-pub",$cacheExpiry,function() use($queryUserUuid){
+        $translationCountPub = RedisClusters::remember("user/{$userName}/translation/count-pub",$cacheExpiry,function() use($queryUserUuid){
                                     return Sentence::where('editor_uid',$queryUserUuid)
                                     ->where('status',30)
                                     ->count();
                                 });
         //术语
-        $termCount = Cache::remember("user/{$userName}/term/count",$cacheExpiry,function() use($queryUserId){
+        $termCount = RedisClusters::remember("user/{$userName}/term/count",$cacheExpiry,function() use($queryUserId){
                         return DhammaTerm::where('editor_id',$queryUserId)
                                     ->count();
                     });
-        $termCountWithNote = Cache::remember("user/{$userName}/term/count-note",$cacheExpiry,function() use($queryUserId){
+        $termCountWithNote = RedisClusters::remember("user/{$userName}/term/count-note",$cacheExpiry,function() use($queryUserId){
                                 return DhammaTerm::where('editor_id',$queryUserId)
                                                     ->where('note',"<>","")
                                                     ->count();
                                 });
         //单词本
-        $myDictCount = Cache::remember("user/{$userName}/dict/count",$cacheExpiry,function() use($queryUserId){
+        $myDictCount = RedisClusters::remember("user/{$userName}/dict/count",$cacheExpiry,function() use($queryUserId){
                             return UserDict::where('creator_id',$queryUserId)
                                         ->count();
                         });

+ 1 - 1
app/Http/Controllers/VocabularyController.php

@@ -22,7 +22,7 @@ class VocabularyController extends Controller
         switch ($request->get("view")) {
             case 'key':
                 $key = $request->get("key");
-                $result = Cache::remember("/dict_vocabulary/{$key}",
+                $result = RedisClusters::remember("/dict_vocabulary/{$key}",
                         config('cache.expire',3600*24),
                         function() use($key){
                         return Vocabulary::whereRaw('word like ? or word_en like ?',[$key."%",$key."%"])

+ 2 - 2
app/Http/Controllers/WbwLookupController.php

@@ -166,12 +166,12 @@ class WbwLookupController extends Controller
                     'case'=>8,
                 ];
         $fieldId = $fieldMap[$field];
-        $myPreference = Cache::get("{$prefix}/{$word}/{$fieldId}/{$userId}");
+        $myPreference = RedisClusters::get("{$prefix}/{$word}/{$fieldId}/{$userId}");
         if(!empty($myPreference)){
             Log::info($word.'命中我的wbw-'.$field);
             return ['value'=>$myPreference,'status'=>5];
         }else{
-            $myPreference = Cache::get("{$prefix}/{$word}/3/0");
+            $myPreference = RedisClusters::get("{$prefix}/{$word}/3/0");
             if(!empty($myPreference)){
                 Log::info($word.'命中社区wbw-'.$field);
                 return ['value'=>$myPreference,'status'=>5];

+ 1 - 1
app/Http/Controllers/WordIndexController.php

@@ -24,7 +24,7 @@ class WordIndexController extends Controller
             case 'key':
                 $key = $request->get("key");
                 /*
-                $result = Cache::remember("/word_index/{$key}",10,function() use($key){
+                $result = RedisClusters::remember("/word_index/{$key}",10,function() use($key){
                     return WordIndex::where('word','like',$key."%")
                                     ->whereOr('word_en','like',$key."%")
                                     ->orderBy('word_en')

+ 1 - 1
app/Http/Resources/SearchResource.php

@@ -35,7 +35,7 @@ class SearchResource extends JsonResource
         }else if(isset($this->content)){
             $data["content"] = $this->content;
         }else{
-            $channelId = Cache::remember('_System_Pali_VRI_',config('cache.expire',3600*24),function(){
+            $channelId = RedisClusters::remember('_System_Pali_VRI_',config('cache.expire',3600*24),function(){
                 return ChannelApi::getSysChannel('_System_Pali_VRI_');
             });