New creates an attestation bundle cache with built-in TTL, bucket, and description.
(ctx context.Context, rc *natsconn.ReloadableConnection, logger log.Logger)
| 39 | |
| 40 | // New creates an attestation bundle cache with built-in TTL, bucket, and description. |
| 41 | func New(ctx context.Context, rc *natsconn.ReloadableConnection, logger log.Logger) (*Cache, error) { |
| 42 | opts := []cache.Option{ |
| 43 | cache.WithTTL(ttl), |
| 44 | cache.WithMaxBytes(maxBytes), |
| 45 | cache.WithDescription(description), |
| 46 | } |
| 47 | |
| 48 | if logger != nil { |
| 49 | opts = append(opts, cache.WithLogger(log.NewHelper(logger))) |
| 50 | } |
| 51 | |
| 52 | if rc != nil { |
| 53 | opts = append(opts, cache.WithNATS(rc.Conn, bucket)) |
| 54 | opts = append(opts, cache.WithReconnect(rc.Subscribe(ctx))) |
| 55 | opts = append(opts, cache.WithReplicas(rc.Replicas)) |
| 56 | } |
| 57 | |
| 58 | c, err := cache.New[[]byte](opts...) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | return &Cache{Cache: c}, nil |
| 63 | } |
no test coverage detected