Documentation
¶
Index ¶
- type Cache
- type Entry
- type KV
- type TypedKV
- func (t *TypedKV[T]) Delete(ctx context.Context, key string) error
- func (t *TypedKV[T]) Get(ctx context.Context, key string) (T, error)
- func (t *TypedKV[T]) Has(ctx context.Context, key string) (bool, error)
- func (t *TypedKV[T]) Set(ctx context.Context, key string, value T) error
- func (t *TypedKV[T]) SetTTL(ctx context.Context, key string, value T, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v0.55.0
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a namespaced, TTL-bound cache over a KV store. It layers cache semantics on top of the storage contract: reads treat every error as a miss (missing/expired keys silently, real failures logged at debug), and write failures are logged rather than surfaced, so callers degrade to uncached behavior instead of handling errors.
func NewCache ¶ added in v0.55.0
NewCache returns a Cache over store, prefixing keys with namespace and expiring entries after ttl. store must be non-nil.
type Entry ¶
type Entry struct {
Key string
Value json.RawMessage
ExpiresAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
Entry represents a raw KV entry with metadata.
type KV ¶
type KV interface {
Get(ctx context.Context, key string, dest any) error
Set(ctx context.Context, key string, value any) error
SetTTL(ctx context.Context, key string, value any, ttl time.Duration) error
Delete(ctx context.Context, key string) error
Has(ctx context.Context, key string) (bool, error)
ListKeys(ctx context.Context) ([]string, error)
GetRaw(ctx context.Context, key string) (Entry, error)
}
KV is the interface for a persistent key-value store. Keys are strings, values are JSON-serializable. Get on a missing key returns an error wrapping sql.ErrNoRows.
type TypedKV ¶
type TypedKV[T any] struct { // contains filtered or unexported fields }
TypedKV provides type-safe access to a KV store for a specific type T.