MCPcopy Create free account
hub / github.com/VersusControl/devops-ai-guidelines / Set

Method Set

02-mcp-for-devops/code/07/pkg/cache/store.go:61–80  ·  view source on GitHub ↗

Set inserts or refreshes a value, evicting the LRU entry when full.

(key string, value any)

Source from the content-addressed store, hash-verified

59
60// Set inserts or refreshes a value, evicting the LRU entry when full.
61func (s *Store) Set(key string, value any) {
62 s.mu.Lock()
63 defer s.mu.Unlock()
64
65 if elem, ok := s.items[key]; ok {
66 e := elem.Value.(*entry)
67 e.value = value
68 e.expiresAt = s.now().Add(s.ttl)
69 s.lru.MoveToFront(elem)
70 return
71 }
72
73 e := &entry{key: key, value: value, expiresAt: s.now().Add(s.ttl)}
74 elem := s.lru.PushFront(e)
75 s.items[key] = elem
76
77 if s.lru.Len() > s.maxSize {
78 s.removeLocked(s.lru.Back())
79 }
80}
81
82// Invalidate drops a single key.
83func (s *Store) Invalidate(key string) {

Callers 2

handleListPodsMethod · 0.80
startDemoHTTPServerFunction · 0.80

Calls 2

removeLockedMethod · 0.95
LenMethod · 0.80

Tested by

no test coverage detected