MCPcopy Create free account
hub / github.com/Facets-cloud/flow / LoadCache

Function LoadCache

internal/stats/cache.go:22–33  ·  view source on GitHub ↗

LoadCache reads a cache file. A missing or corrupt file yields an empty (usable) cache — never an error. Stats must never fail on a bad cache.

(path string)

Source from the content-addressed store, hash-verified

20// LoadCache reads a cache file. A missing or corrupt file yields an empty
21// (usable) cache — never an error. Stats must never fail on a bad cache.
22func LoadCache(path string) *Cache {
23 c := &Cache{Entries: map[string]cacheEntry{}}
24 data, err := os.ReadFile(path)
25 if err != nil {
26 return c
27 }
28 var loaded Cache
29 if err := json.Unmarshal(data, &loaded); err != nil || loaded.Entries == nil {
30 return c
31 }
32 return &loaded
33}
34
35// Save writes the cache as JSON.
36func (c *Cache) Save(path string) error {

Callers 6

cmdStatsFunction · 0.92
TestBuildStatsEndToEndFunction · 0.85
TestBuildStatsWindowedFunction · 0.85
TestLoadCacheCorruptFunction · 0.85

Calls

no outgoing calls

Tested by 5

TestBuildStatsEndToEndFunction · 0.68
TestBuildStatsWindowedFunction · 0.68
TestLoadCacheCorruptFunction · 0.68