github.com/anchore/syft@v1.38.2/internal/cache/cache.go (about) 1 package cache 2 3 import ( 4 "io" 5 ) 6 7 // Manager is responsible for managing cache data and instantiating all caches 8 type Manager interface { 9 // GetCache returns a cache scoped to the given named, versioned data 10 GetCache(name, version string) Cache 11 12 // RootDirs returns any root directories this cache manager uses 13 RootDirs() []string 14 } 15 16 // ReaderAtCloser is an amalgamation of: io.Reader, io.ReaderAt, and io.Closer 17 type ReaderAtCloser interface { 18 io.Reader 19 io.ReaderAt 20 io.Closer 21 } 22 23 // Cache is what the application interacts with to get and set cached data 24 type Cache interface { 25 // Read returns a reader for the cache value, if found and not expired 26 // or errors when unable to find / expired 27 Read(key string) (ReaderAtCloser, error) 28 29 // Write writes the contents of the reader to the cache 30 // and closes it, if the reader implements io.Closer 31 Write(key string, contents io.Reader) error 32 } 33 34 // GetManager returns the global cache manager, which is used to instantiate all caches 35 func GetManager() Manager { 36 return manager 37 } 38 39 // SetManager sets the global cache manager, which is used to instantiate all caches. 40 // Setting this to nil disables caching. 41 func SetManager(m Manager) { 42 if m == nil { 43 manager = &bypassedCache{} 44 } else { 45 manager = m 46 } 47 } 48 49 var manager Manager = &bypassedCache{}