0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-23 22:27:35 -05:00
zot/pkg/extensions/search/cve/trivy/cache.go
Andrei Aaron e04d98272c
chore: update the version of go-lru we use to the latest available (#1141)
We are now using v2.0.1 in the cve cache logic.
Unfortunately we are also using v0.5.4 indirectly, as it is required for gqlgen, see:
e6114a2c6a/go.mod (L7)

Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
2023-01-26 11:14:17 -08:00

36 lines
753 B
Go

package trivy
import (
lru "github.com/hashicorp/golang-lru/v2"
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
"zotregistry.io/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) 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()
}