natscache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NatsKV

type NatsKV struct {
	// contains filtered or unexported fields
}

NatsKV provides a remote cache backed by NATS JetStream KeyValue with built-in distributed stampede locking and real-time Watch invalidations.

func New

func New(kv jetstream.KeyValue) *NatsKV

New returns a new NATS JetStream KeyValue cache level.

func (*NatsKV) Add

func (n *NatsKV) Add(ctx context.Context, k entcache.Key, e *entcache.Entry, ttl time.Duration) error

Add adds the entry to the cache using Put or Create for per-key TTL.

func (*NatsKV) Del

func (n *NatsKV) Del(ctx context.Context, k entcache.Key) error

Del deletes an entry from the cache.

func (*NatsKV) Get

func (n *NatsKV) Get(ctx context.Context, k entcache.Key) (*entcache.Entry, error)

Get gets an entry from the cache.

func (*NatsKV) LockOrWait

func (n *NatsKV) LockOrWait(ctx context.Context, k entcache.Key) (bool, func(context.Context) (*entcache.Entry, error), func(context.Context), error)

LockOrWait acquires a distributed lock on cache misses using NATS KV Create. If won == true, the caller executes the DB query and releases the lock. If won == false, wait() uses Watch to wait until the winner populates the cache.

func (*NatsKV) WatchInvalidations

func (n *NatsKV) WatchInvalidations(ctx context.Context, onInvalidate func(key entcache.Key)) error

WatchInvalidations listens to NATS KV key updates/deletions and triggers onInvalidate.

Jump to

Keyboard shortcuts

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