MCPcopy
hub / github.com/rclone/rclone / Get

Method Get

lib/cache/cache.go:83–105  ·  view source on GitHub ↗

Get gets a value named key either from the cache or creates it afresh with the create function.

(key string, create CreateFunc)

Source from the content-addressed store, hash-verified

81// Get gets a value named key either from the cache or creates it
82// afresh with the create function.
83func (c *Cache) Get(key string, create CreateFunc) (value any, err error) {
84 c.mu.Lock()
85 entry, ok := c.cache[key]
86 if !ok {
87 c.mu.Unlock() // Unlock in case Get is called recursively
88 value, ok, err = create(key)
89 if err != nil && !ok {
90 return value, err
91 }
92 entry = &cacheEntry{
93 value: value,
94 key: key,
95 err: err,
96 }
97 c.mu.Lock()
98 if !c.noCache() {
99 c.cache[key] = entry
100 }
101 }
102 defer c.mu.Unlock()
103 c.used(entry)
104 return entry.value, entry.err
105}
106
107func (c *Cache) addPin(key string, count int) {
108 c.mu.Lock()

Callers

nothing calls this directly

Calls 5

noCacheMethod · 0.95
usedMethod · 0.95
createFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected