0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00
zot/pkg/extensions/search/cve/cache/cache.go
Andrei Aaron ce4924f841
refactor: rename go module from zotregistry.io/zot to zotregistry.dev/zot (#2187)
Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
2024-01-31 20:34:07 -08:00

40 lines
853 B
Go

package cache
import (
lru "github.com/hashicorp/golang-lru/v2"
cvemodel "zotregistry.dev/zot/pkg/extensions/search/cve/model"
"zotregistry.dev/zot/pkg/log"
)
type CveCache struct {
cache *lru.Cache[string, map[string]cvemodel.CVE]
log log.Logger
}
func NewCveCache(size int, log log.Logger) *CveCache {
cache, _ := lru.New[string, map[string]cvemodel.CVE](size)
return &CveCache{cache: cache, log: log}
}
func (cveCache *CveCache) Add(image string, cveMap map[string]cvemodel.CVE) {
cveCache.cache.Add(image, cveMap)
}
func (cveCache *CveCache) Contains(image string) bool {
return cveCache.cache.Contains(image)
}
func (cveCache *CveCache) Get(image string) map[string]cvemodel.CVE {
cveMap, ok := cveCache.cache.Get(image)
if !ok {
return nil
}
return cveMap
}
func (cveCache *CveCache) Purge() {
cveCache.cache.Purge()
}