Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f27a9a4

Browse files
author
xuxinhua
committed
top cache
1 parent 7c71bb4 commit f27a9a4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

internal/dao/cache/feed.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func (feedCache) GetTop(ctx context.Context) []*model.Feed {
2222
return nil
2323
}
2424

25+
if s == "notop" {
26+
return []*model.Feed{}
27+
}
28+
2529
feeds := make([]*model.Feed, 0)
2630
err := json.Unmarshal([]byte(s), &feeds)
2731
if err != nil {
@@ -35,8 +39,13 @@ func (feedCache) SetTop(ctx context.Context, feeds []*model.Feed) {
3539
redisClient := nosql.NewRedisClient()
3640
defer redisClient.Close()
3741

38-
b, _ := json.Marshal(feeds)
39-
redisClient.SET("feed:top", string(b), 300)
42+
val := "notop"
43+
if len(feeds) > 0 {
44+
b, _ := json.Marshal(feeds)
45+
val = string(b)
46+
}
47+
48+
redisClient.SET("feed:top", val, 300)
4049
}
4150

4251
func (feedCache) GetList(ctx context.Context, p int) []*model.Feed {

internal/logic/feed.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (self FeedLogic) FindTop(ctx context.Context) []*model.Feed {
8080
objLog := GetLogger(ctx)
8181

8282
feeds := cache.Feed.GetTop(ctx)
83-
if len(feeds) > 0 {
83+
if feeds != nil {
8484
return feeds
8585
}
8686

@@ -92,9 +92,7 @@ func (self FeedLogic) FindTop(ctx context.Context) []*model.Feed {
9292
}
9393

9494
feeds = self.fillOtherInfo(ctx, feeds, false)
95-
if len(feeds) > 0 {
96-
cache.Feed.SetTop(ctx, feeds)
97-
}
95+
cache.Feed.SetTop(ctx, feeds)
9896
return feeds
9997
}
10098

0 commit comments

Comments
 (0)