瀏覽代碼

feat:列表缓存时间修改

wangkaiyue 1 年之前
父節點
當前提交
f9f277ad49
共有 3 個文件被更改,包括 14 次插入5 次删除
  1. 9 1
      internal/consts/vars.go
  2. 4 2
      internal/service/queryStruct.go
  3. 1 2
      internal/service/strategy.go

+ 9 - 1
internal/consts/vars.go

@@ -2,6 +2,7 @@ package consts
 
 
 import (
 import (
 	"context"
 	"context"
+	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
 )
 )
 
 
@@ -12,7 +13,6 @@ var (
 	KeyWordSiteMaxTotal       = g.Cfg().MustGet(context.Background(), "listPageSetting.KeyWordSiteMaxTotal", 300).Int()
 	KeyWordSiteMaxTotal       = g.Cfg().MustGet(context.Background(), "listPageSetting.KeyWordSiteMaxTotal", 300).Int()
 	KeyWordEsMatchingDegree   = g.Cfg().MustGet(context.Background(), "listPageSetting.MatchingDegree", "10%").String()
 	KeyWordEsMatchingDegree   = g.Cfg().MustGet(context.Background(), "listPageSetting.MatchingDegree", "10%").String()
 	KeyWordPinyinMaxTotal     = g.Cfg().MustGet(context.Background(), "listPageSetting.KeyWordPinyinMaxTotal", 300).Int()
 	KeyWordPinyinMaxTotal     = g.Cfg().MustGet(context.Background(), "listPageSetting.KeyWordPinyinMaxTotal", 300).Int()
-	SettingBidCacheTime       = g.Cfg().MustGet(context.Background(), "listPageSetting.cacheTime", 43200).Int64()
 	TopTypeMap                = map[string]string{
 	TopTypeMap                = map[string]string{
 		"招标预告":   "预告",
 		"招标预告":   "预告",
 		"招标公告":   "招标",
 		"招标公告":   "招标",
@@ -42,3 +42,11 @@ const (
 	ReportHistoryTable = "marketAnalysisReport"
 	ReportHistoryTable = "marketAnalysisReport"
 	AnalysisReport     = "analysis_report"
 	AnalysisReport     = "analysis_report"
 )
 )
+
+func GetListCacheTime(ctx context.Context, flag string) int64 {
+	v := g.Cfg().MustGet(ctx, fmt.Sprintf("listPageSetting.cacheTime.%s", flag)).Int64()
+	if v > 0 {
+		return v
+	}
+	return g.Cfg().MustGet(context.Background(), "listPageSetting.cacheTime.default", 43200).Int64()
+}

+ 4 - 2
internal/service/queryStruct.go

@@ -207,7 +207,8 @@ func (query *SeoBiddingQuery) GetDataPageList(ctx context.Context, pageNum, page
 				if i == pageNum {
 				if i == pageNum {
 					res = pageTmp
 					res = pageTmp
 				}
 				}
-				if err := g.Redis().SetEX(ctx, query.getDataPageListCacheKey(i, pageSize, maxTotal, flag), pageTmp, g.Cfg().MustGet(ctx, "listPageSetting.cacheTime.STypePageHandler", consts.SettingBidCacheTime).Int64()); err != nil {
+				fmt.Println(query.getDataPageListCacheKey(i, pageSize, maxTotal, flag), consts.GetListCacheTime(ctx, flag))
+				if err := g.Redis().SetEX(ctx, query.getDataPageListCacheKey(i, pageSize, maxTotal, flag), pageTmp, consts.GetListCacheTime(ctx, flag)); err != nil {
 					g.Log().Errorf(ctx, "第%d页数据 存储redis err:%v", err)
 					g.Log().Errorf(ctx, "第%d页数据 存储redis err:%v", err)
 				}
 				}
 			}
 			}
@@ -247,7 +248,8 @@ func (query *SeoBiddingQuery) GetOnceData(ctx context.Context, total int, flag s
 		if len(res) > total {
 		if len(res) > total {
 			res = res[:total]
 			res = res[:total]
 		}
 		}
-		if err := g.Redis().SetEX(ctx, cacheKey, res, g.Cfg().MustGet(ctx, "listPageSetting.cacheTime.STypePageHandler", consts.SettingBidCacheTime).Int64()); err != nil {
+		fmt.Println(cacheKey, consts.GetListCacheTime(ctx, flag))
+		if err := g.Redis().SetEX(ctx, cacheKey, res, consts.GetListCacheTime(ctx, flag)); err != nil {
 			g.Log().Errorf(ctx, "GetOnceData 存储redis err:%v", err)
 			g.Log().Errorf(ctx, "GetOnceData 存储redis err:%v", err)
 		}
 		}
 	} else {
 	} else {

+ 1 - 2
internal/service/strategy.go

@@ -7,7 +7,6 @@ import (
 	"fmt"
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
 	"html/template"
 	"html/template"
-	"jyseo/internal/consts"
 	"jyseo/utility"
 	"jyseo/utility"
 	"time"
 	"time"
 
 
@@ -123,6 +122,6 @@ func GetStrategyList(num int) (res []*InfoList) {
 			v["_id"] = se.EncodeString(gconv.String(v["_id"]))
 			v["_id"] = se.EncodeString(gconv.String(v["_id"]))
 		}
 		}
 	}
 	}
-	_ = g.Redis().SetEX(ctx, cacheKey, res, consts.SettingBidCacheTime)
+	_ = g.Redis().SetEX(ctx, cacheKey, res, 43200)
 	return res
 	return res
 }
 }