MCPcopy Index your code
hub / github.com/perkeep/perkeep / Add

Method Add

internal/lru/cache.go:61–81  ·  view source on GitHub ↗

Add adds the provided key and value to the cache, evicting an old item if necessary.

(key string, value interface{})

Source from the content-addressed store, hash-verified

59// Add adds the provided key and value to the cache, evicting
60// an old item if necessary.
61func (c *Cache) Add(key string, value interface{}) {
62 if !c.nolock {
63 c.mu.Lock()
64 defer c.mu.Unlock()
65 }
66
67 // Already in cache?
68 if ee, ok := c.cache[key]; ok {
69 c.ll.MoveToFront(ee)
70 ee.Value.(*entry).value = value
71 return
72 }
73
74 // Add to cache if not present
75 ele := c.ll.PushFront(&entry{key, value})
76 c.cache[key] = ele
77
78 if c.maxEntries > 0 && c.ll.Len() > c.maxEntries {
79 c.removeOldest()
80 }
81}
82
83// Get fetches the key's value from the cache.
84// The ok result will be true if the item was found.

Callers 8

NewWorkerFunction · 0.45
GenSelfTLSFunction · 0.45
TestLRUFunction · 0.45
TestRemoveOldestFunction · 0.45
AwaitReachableFunction · 0.45
TestHalveInplaceFunction · 0.45
HalveInplaceFunction · 0.45
DecodeDownsampleFunction · 0.45

Calls 4

removeOldestMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
LenMethod · 0.65

Tested by 3

TestLRUFunction · 0.36
TestRemoveOldestFunction · 0.36
TestHalveInplaceFunction · 0.36