2023-01-17 16:14:17 -05:00
|
|
|
package trivy
|
|
|
|
|
|
|
|
import (
|
2023-01-26 14:14:17 -05:00
|
|
|
lru "github.com/hashicorp/golang-lru/v2"
|
2023-01-17 16:14:17 -05:00
|
|
|
|
|
|
|
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CveCache struct {
|
2023-01-26 14:14:17 -05:00
|
|
|
cache *lru.Cache[string, map[string]cvemodel.CVE]
|
2023-01-17 16:14:17 -05:00
|
|
|
log log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCveCache(size int, log log.Logger) *CveCache {
|
2023-01-26 14:14:17 -05:00
|
|
|
cache, _ := lru.New[string, map[string]cvemodel.CVE](size)
|
2023-01-17 16:14:17 -05:00
|
|
|
|
|
|
|
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 {
|
2023-01-26 14:14:17 -05:00
|
|
|
cveMap, ok := cveCache.cache.Get(image)
|
2023-01-17 16:14:17 -05:00
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cveMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cveCache *CveCache) Purge() {
|
|
|
|
cveCache.cache.Purge()
|
|
|
|
}
|