MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / setCache

Function setCache

pkg/suggestion/filewalk.go:84–113  ·  view source on GitHub ↗
(key string, value []DirEntryResult)

Source from the content-addressed store, hash-verified

82}
83
84func setCache(key string, value []DirEntryResult) {
85 cacheMu.Lock()
86 defer cacheMu.Unlock()
87 // if already exists, update it
88 if entry, ok := cache[key]; ok {
89 entry.value = value
90 entry.expiration = time.Now().Add(cacheTTL)
91 cacheLRU.MoveToFront(entry.lruElement)
92 return
93 }
94 // evict if at capacity
95 if cacheLRU.Len() >= maxCacheEntries {
96 oldest := cacheLRU.Back()
97 if oldest != nil {
98 oldestKey := oldest.Value.(string)
99 if oldEntry, ok := cache[oldestKey]; ok {
100 cacheLRU.Remove(oldEntry.lruElement)
101 delete(cache, oldestKey)
102 }
103 }
104 }
105 // add new entry
106 elem := cacheLRU.PushFront(key)
107 cache[key] = &cacheEntry{
108 key: key,
109 value: value,
110 expiration: time.Now().Add(cacheTTL),
111 lruElement: elem,
112 }
113}
114
115// cacheDispose clears all cache entries for the provided widgetId.
116func cacheDispose(widgetId string) {

Callers 1

listDirectoryFunction · 0.85

Calls 1

LenMethod · 0.80

Tested by

no test coverage detected