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 ¶
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.
Click to show internal directories.
Click to hide internal directories.