MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / New

Function New

pkg/cache/cache.go:100–122  ·  view source on GitHub ↗

New creates a new Cache[T]. If NATS options are provided and the connection is non-nil, a NATS KV backend is returned. Otherwise an in-memory LRU is used.

(opts ...Option)

Source from the content-addressed store, hash-verified

98// New creates a new Cache[T]. If NATS options are provided and the connection
99// is non-nil, a NATS KV backend is returned. Otherwise an in-memory LRU is used.
100func New[T any](opts ...Option) (Cache[T], error) {
101 cfg := &config{}
102 for _, o := range opts {
103 o(cfg)
104 }
105
106 if cfg.ttl <= 0 {
107 return nil, errors.New("cache: TTL must be greater than 0")
108 }
109
110 if cfg.logger == nil {
111 cfg.logger = nopLogger{}
112 }
113
114 if cfg.natsConn != nil {
115 if cfg.bucketName == "" {
116 return nil, errors.New("cache: bucket name is required when NATS backend is enabled")
117 }
118 return newNATSKV[T](cfg)
119 }
120
121 return newMemoryCache[T](cfg), nil
122}
123
124// nopLogger is a no-op implementation of Logger.
125type nopLogger struct{}

Callers 8

NewFunction · 0.92
NewFunction · 0.92
newClaimsCacheFunction · 0.92
newMembershipsCacheFunction · 0.92
newClaimsCacheFunction · 0.92
newMembershipsCacheFunction · 0.92

Calls

no outgoing calls