Documentation
¶
Overview ¶
Package memory supplies a bounded, concurrency-safe cache backend for local development and deterministic tests. It does not provide distributed guarantees.
Index ¶
- type Backend
- func (b *Backend) Add(ctx context.Context, key cache.EntryKey, data []byte, ttl cache.TTL) (bool, error)
- func (b *Backend) AddTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) (bool, error)
- func (b *Backend) Close(ctx context.Context) error
- func (b *Backend) Exists(ctx context.Context, key cache.EntryKey) (bool, error)
- func (b *Backend) ExistsTagged(ctx context.Context, key cache.TaggedKey) (bool, error)
- func (b *Backend) Expire(ctx context.Context, key cache.EntryKey, ttl cache.TTL) (bool, error)
- func (b *Backend) ExpireTagged(ctx context.Context, key cache.TaggedKey, ttl cache.TTL) (bool, error)
- func (b *Backend) Forget(ctx context.Context, key cache.EntryKey) (bool, error)
- func (b *Backend) ForgetMany(ctx context.Context, keys []cache.EntryKey) (uint64, error)
- func (b *Backend) ForgetManyTagged(ctx context.Context, keys []cache.TaggedKey) (uint64, error)
- func (b *Backend) ForgetTagged(ctx context.Context, key cache.TaggedKey) (bool, error)
- func (*Backend) FoundryAdapter(frameworkadapter.Seal)
- func (b *Backend) Get(ctx context.Context, key cache.EntryKey) ([]byte, bool, error)
- func (b *Backend) GetMany(ctx context.Context, keys []cache.EntryKey) ([]cache.BatchValue, error)
- func (b *Backend) GetManyTagged(ctx context.Context, keys []cache.TaggedKey) ([]cache.BatchValue, error)
- func (b *Backend) GetTagged(ctx context.Context, key cache.TaggedKey) ([]byte, bool, error)
- func (b *Backend) Increment(ctx context.Context, key cache.EntryKey, delta int64, initialTTL cache.TTL) (int64, error)
- func (b *Backend) IncrementTagged(ctx context.Context, key cache.TaggedKey, delta int64, ttl cache.TTL) (int64, error)
- func (b *Backend) InvalidateTags(ctx context.Context, keys []cache.EntryKey) error
- func (b *Backend) Put(ctx context.Context, key cache.EntryKey, data []byte, ttl cache.TTL) error
- func (b *Backend) PutTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) error
- func (b *Backend) ResolveTags(ctx context.Context, keys []cache.EntryKey) ([]cache.TagVersion, error)
- func (b *Backend) Stats() Stats
- type Config
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend owns immutable serialized snapshots and their expiry/LRU indexes. New performs no I/O and starts no goroutines. Close rejects new operations and releases this backend's memory; typed Store handles borrow this capability. Reads share a read lock and never reorder storage: they mark entries referenced, and expired or unusable entries they meet are reclaimed later by writes, capacity pressure or Stats. Mutations take the exclusive lock.
func (*Backend) ExistsTagged ¶
func (*Backend) ExpireTagged ¶
func (*Backend) ForgetMany ¶
func (*Backend) ForgetManyTagged ¶
func (*Backend) ForgetTagged ¶
func (*Backend) FoundryAdapter ¶
func (*Backend) FoundryAdapter(frameworkadapter.Seal)
FoundryAdapter marks the backend as framework-owned adapter I/O.
func (*Backend) GetMany ¶
GetMany reads a canonical batch under one shared lock; results follow input order.
func (*Backend) GetManyTagged ¶
func (b *Backend) GetManyTagged(ctx context.Context, keys []cache.TaggedKey) ([]cache.BatchValue, error)
GetManyTagged validates one shared snapshot and reads the batch atomically.
func (*Backend) Increment ¶
func (b *Backend) Increment(ctx context.Context, key cache.EntryKey, delta int64, initialTTL cache.TTL) (int64, error)
Increment changes the same entry used by the other cache operations, under the same mutex. Existing expiry is preserved and failures leave its data unchanged.
func (*Backend) IncrementTagged ¶
func (*Backend) InvalidateTags ¶
func (*Backend) ResolveTags ¶
func (b *Backend) ResolveTags(ctx context.Context, keys []cache.EntryKey) ([]cache.TagVersion, error)
ResolveTags reads existing metadata under the shared lock and takes the exclusive lock only when a version must be created.
type Config ¶
Config bounds both entry count and the sum of physical-key and payload bytes. Map/list overhead is additionally bounded by MaxEntries. Recency eviction (LRU with a second chance for entries read since they were last ordered) applies after expired entries have been reclaimed. An oversized entry is rejected.
func DefaultConfig ¶
func DefaultConfig() Config