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

Method GetCache

internal/repository/cache/relation.go:31–48  ·  view source on GitHub ↗
(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

29}
30
31func (c *relationCache) GetCache(ctx context.Context, key string) ([]domain.Relation, error) {
32 // 从Redis获取数据
33 data, err := c.client.Get(ctx, key).Result()
34 if errors.Is(err, redis.Nil) {
35 return nil, nil // 缓存未命中
36 } else if err != nil {
37 return nil, err // Redis调用失败
38 }
39
40 // 解码数据
41 var relations []domain.Relation
42
43 if err := json.Unmarshal([]byte(data), &relations); err != nil {
44 return nil, err
45 }
46
47 return relations, nil
48}
49
50func (c *relationCache) SetCache(ctx context.Context, key string, relations []domain.Relation, ttl time.Duration) error {
51 // 编码数据为JSON格式

Callers

nothing calls this directly

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected