MCPcopy
hub / github.com/grafana/dskit / Add

Method Add

cache/lru.go:125–143  ·  view source on GitHub ↗
(ctx context.Context, key string, value []byte, ttl time.Duration)

Source from the content-addressed store, hash-verified

123}
124
125func (l *LRUCache) Add(ctx context.Context, key string, value []byte, ttl time.Duration) error {
126 err := l.c.Add(ctx, key, value, ttl)
127
128 // When a caller uses the Add method, the presence of absence of an entry in the cache
129 // has significance. In order to maintain the semantics of that, we only add an entry to
130 // the LRU when it was able to be successfully added to the shared cache.
131 if err == nil {
132 l.mtx.Lock()
133 defer l.mtx.Unlock()
134
135 expires := time.Now().Add(ttl)
136 l.lru.Add(key, &Item{
137 Data: value,
138 ExpiresAt: expires,
139 })
140 }
141
142 return err
143}
144
145func (l *LRUCache) GetMulti(ctx context.Context, keys []string, opts ...Option) (result map[string][]byte) {
146 result, err := l.GetMultiWithError(ctx, keys, opts...)

Callers

nothing calls this directly

Calls 1

AddMethod · 0.65

Tested by

no test coverage detected