MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / Set

Method Set

internal/repository/cache/local.go:39–56  ·  view source on GitHub ↗
(ctx context.Context, posts []domain.Post)

Source from the content-addressed store, hash-verified

37}
38
39func (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
58func (r *rankingLocalCache) Get(ctx context.Context) ([]domain.Post, error) {
59 r.mu.RLock()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected