cache

package
v1.89.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] interface {
	Get(ctx context.Context, key string) (T, bool, error)
	Set(ctx context.Context, key string, value T) error
	Delete(ctx context.Context, key string) error
	Purge(ctx context.Context) error
}

Cache is a generic cache interface with TTL-based expiration. TTL is configured at construction time, not per-operation.

func New

func New[T any](opts ...Option) (Cache[T], error)

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.

type Logger

type Logger interface {
	Debugw(keyvals ...any)
	Warnw(keyvals ...any)
	Infow(keyvals ...any)
	Errorw(keyvals ...any)
}

Logger is a structured logging interface satisfied by *log.Helper from Kratos.

type Option

type Option func(*config)

Option configures cache construction.

func WithDescription

func WithDescription(desc string) Option

WithDescription sets the NATS KV bucket description. Ignored for in-memory backend.

func WithLogger

func WithLogger(l Logger) Option

WithLogger sets a structured logger for cache operations.

func WithMaxBytes added in v1.89.12

func WithMaxBytes(n int64) Option

WithMaxBytes sets the maximum total size (in bytes) for the NATS KV bucket. When the limit is reached, NATS discards the oldest entries. Ignored for in-memory backend.

func WithNATS

func WithNATS(conn *nats.Conn, bucketName string) Option

WithNATS enables the NATS JetStream KV backend.

func WithReconnect

func WithReconnect(ch <-chan struct{}) Option

WithReconnect provides a channel that signals NATS reconnection events.

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the expiration duration for cache entries. Required.

Directories

Path Synopsis
Package attestationbundle provides a typed cache for attestation bundles.
Package attestationbundle provides a typed cache for attestation bundles.
Package policyevalbundle provides a typed cache for policy evaluation bundles.
Package policyevalbundle provides a typed cache for policy evaluation bundles.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL