MCPcopy Create free account
hub / github.com/Azure/peerd / Exists

Method Exists

pkg/cache/filecache.go:32–47  ·  view source on GitHub ↗

Exists checks if the file exists in the cache.

(name string, offset int64)

Source from the content-addressed store, hash-verified

30
31// Exists checks if the file exists in the cache.
32func (c *fileCache) Exists(name string, offset int64) bool {
33 key := c.getKey(name, offset)
34 val, found := c.fileCache.Get(key)
35 if found {
36 cacheItem := val.(*item)
37 cacheItem.lock.Lock()
38 defer cacheItem.lock.Unlock()
39
40 if info, err := cacheItem.file.Stat(); err != nil {
41 return false
42 } else {
43 return info.Size() > 0
44 }
45 }
46 return false
47}
48
49// GetOrCreate gets the cached value if available, otherwise fetches it.
50func (c *fileCache) GetOrCreate(name string, alignedOffset int64, count int, fetch func() ([]byte, error)) ([]byte, error) {

Callers

nothing calls this directly

Calls 3

getKeyMethod · 0.95
SizeMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected