Documentation
¶
Index ¶
- type NatsKV
- func (n *NatsKV) Add(ctx context.Context, k entcache.Key, e *entcache.Entry, ttl time.Duration) error
- func (n *NatsKV) Del(ctx context.Context, k entcache.Key) error
- func (n *NatsKV) Get(ctx context.Context, k entcache.Key) (*entcache.Entry, error)
- func (n *NatsKV) LockOrWait(ctx context.Context, k entcache.Key) (bool, func(context.Context) (*entcache.Entry, error), func(context.Context), ...)
- func (n *NatsKV) WatchInvalidations(ctx context.Context, onInvalidate func(key entcache.Key)) error
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 (*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) 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.
Click to show internal directories.
Click to hide internal directories.