(ctx context.Context, posts []domain.Post)
| 37 | } |
| 38 | |
| 39 | func (r *rankingLocalCache) Set(ctx context.Context, posts []domain.Post) error { |
| 40 | if len(posts) == 0 { |
| 41 | r.logger.Warn("试图设置空缓存") |
| 42 | return ErrCacheEmpty |
| 43 | } |
| 44 | |
| 45 | r.mu.Lock() |
| 46 | defer r.mu.Unlock() |
| 47 | |
| 48 | r.posts = make([]domain.Post, len(posts)) |
| 49 | copy(r.posts, posts) |
| 50 | r.expireAt = time.Now().Add(r.ttl) |
| 51 | |
| 52 | r.logger.Info("本地缓存已更新", |
| 53 | zap.Int("post_count", len(posts)), |
| 54 | zap.Time("expire_at", r.expireAt)) |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func (r *rankingLocalCache) Get(ctx context.Context) ([]domain.Post, error) { |
| 59 | r.mu.RLock() |
nothing calls this directly
no outgoing calls
no test coverage detected