mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 23:26:39 -08:00
feat: add memory cache backend (#7048)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
8
pkg/cache/client.go
vendored
8
pkg/cache/client.go
vendored
@@ -5,12 +5,15 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeUnknown Type = "unknown"
|
||||
TypeFS Type = "fs"
|
||||
TypeRedis Type = "redis"
|
||||
TypeMemory Type = "memory"
|
||||
)
|
||||
|
||||
type Type string
|
||||
@@ -33,6 +36,8 @@ func NewType(backend string) Type {
|
||||
return TypeRedis
|
||||
case backend == "fs", backend == "":
|
||||
return TypeFS
|
||||
case backend == "memory":
|
||||
return TypeMemory
|
||||
default:
|
||||
return TypeUnknown
|
||||
}
|
||||
@@ -44,6 +49,7 @@ func New(opts Options) (Cache, func(), error) {
|
||||
|
||||
var cache Cache
|
||||
t := NewType(opts.Backend)
|
||||
log.Debug("Initializing scan cache...", log.String("type", string(t)))
|
||||
switch t {
|
||||
case TypeRedis:
|
||||
redisCache, err := NewRedisCache(opts.Backend, opts.RedisCACert, opts.RedisCert, opts.RedisKey, opts.RedisTLS, opts.TTL)
|
||||
@@ -58,6 +64,8 @@ func New(opts Options) (Cache, func(), error) {
|
||||
return nil, cleanup, xerrors.Errorf("unable to initialize fs cache: %w", err)
|
||||
}
|
||||
cache = fsCache
|
||||
case TypeMemory:
|
||||
cache = NewMemoryCache()
|
||||
default:
|
||||
return nil, cleanup, xerrors.Errorf("unknown cache type: %s", t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user