natscache

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package natscache provides a NATS JetStream KeyValue-backed cache.Store implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) cachecore.Store

New builds a NATS-backed cachecore.Store.

Defaults: - DefaultTTL: 5*time.Minute when zero - Prefix: "app" when empty - BucketTTL: false (TTL enforced in value envelope metadata) - KeyValue: required for real operations (nil allowed, operations return errors)

Example: inject NATS key-value bucket via explicit driver config

var kv natscache.KeyValue // provided by your NATS setup
store := natscache.New(natscache.Config{
	BaseConfig: cachecore.BaseConfig{
		DefaultTTL: 5 * time.Minute,
		Prefix:     "app",
	},
	KeyValue:  kv,
	BucketTTL: false,
})
fmt.Println(store.Driver()) // nats

Types

type Config

type Config struct {
	cachecore.BaseConfig
	KeyValue  KeyValue
	BucketTTL bool
}

Config configures a NATS JetStream KeyValue-backed cache store.

type KeyValue

type KeyValue interface {
	Status() (nats.KeyValueStatus, error)
	Get(key string) (nats.KeyValueEntry, error)
	Put(key string, value []byte) (uint64, error)
	Create(key string, value []byte) (uint64, error)
	Update(key string, value []byte, last uint64) (uint64, error)
	Delete(key string, opts ...nats.DeleteOpt) error
	Purge(key string, opts ...nats.DeleteOpt) error
	ListKeys(opts ...nats.WatchOpt) (nats.KeyLister, error)
}

KeyValue captures the subset of nats.KeyValue used by the store.

Jump to

Keyboard shortcuts

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