浏览代码

首页热门缓存

wangkaiyue 4 年之前
父节点
当前提交
43c596a08f
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      jydocs-back/servers/stdDoc.go

+ 10 - 1
jydocs-back/servers/stdDoc.go

@@ -4,6 +4,7 @@ import (
 	. "app.yhyue.com/moapp/jybase/api"
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jybase/redis"
 	"fmt"
 	"jy-docs/config"
 	"jy-docs/public"
@@ -176,11 +177,19 @@ func (stdDoc *StdDoc) TopList() {
 		} else {
 			return nil, fmt.Errorf("未知请求")
 		}
-		//存入redis缓存
+		topKey := fmt.Sprintf("jydoc_indexCache_%s_%d", reqSort, num)
+		listCache := redis.Get("other", topKey)
+		if listCache != nil {
+			return listCache, nil
+		}
+		log.Println("flush", topKey)
 		list, _, err := rpc.GetDocQuery(userId, "", "", 1, num, reqSort)
 		if err != nil {
 			return nil, err
 		}
+		if len(list) > 0 { //存入redis缓存
+			redis.Put("other", topKey, list, 60*5)
+		}
 		return list, nil
 	}()
 	if errMsg != nil {