// Memory Provider for the oci cache // this provider is based on an arc cache // ARCCache is a thread-safe fixed size Adaptive Replacement Cache (ARC) // ARC is an enhancement over the standard LRU cache in that tracks both frequency and recency of use package memory import ( v1 "github.com/google/go-containerregistry/pkg/v1" lru "github.com/hashicorp/golang-lru" ) // ArcCache encapsulates an arc cache to store oci artifacts. type ArcCache struct { store *lru.ARCCache } // New returns a new instance of the memory provider. func New(limit int) (*ArcCache, error) { cache, err := lru.NewARC(limit) if err != nil { return nil, err } return &ArcCache{cache}, nil } // Get fetches an object from the arc cache if it exists func (m *ArcCache) Get(h v1.Hash) (any, bool) { return m.store.Get(h) } // Keys returns the set of cache keys in the backing store func (m *ArcCache) Keys() []any { return m.store.Keys() } // Exists check if the artifact with the specified hash exists in the arc cache func (m *ArcCache) Exists(h v1.Hash) bool { return m.store.Contains(h) } // Add inserts an artifact to the arc cache func (m *ArcCache) Add(h v1.Hash, obj any) { m.store.Add(h, obj) } // Len returns number of entries in cache. func (m *ArcCache) Len() int { return m.store.Len() } func (m *ArcCache) Purge() { m.store.Purge() }