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) Add ¶
func (b *Backend) Add(ctx context.Context, key cache.EntryKey, data []byte, ttl cache.TTL) (bool, error)
Add atomically copies and inserts an absent entry, retaining an existing live value and TTL.
func (*Backend) AddTagged ¶
func (b *Backend) AddTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) (bool, error)
AddTagged atomically inserts only when the current snapshot has no live value.
func (*Backend) Close ¶
Close rejects new operations and releases retained entries. Repeated calls are safe.
func (*Backend) Exists ¶
Exists reports whether a usable live plain entry exists without copying its payload.
func (*Backend) ExistsTagged ¶
ExistsTagged checks a live entry under its tag snapshot, returning fault.Conflict for stale metadata.
func (*Backend) ExpireTagged ¶
func (b *Backend) ExpireTagged(ctx context.Context, key cache.TaggedKey, ttl cache.TTL) (bool, error)
ExpireTagged atomically validates the tag snapshot and changes a live entry's TTL.
func (*Backend) ForgetMany ¶
ForgetMany validates and atomically removes a canonical batch, counting live entries.
func (*Backend) ForgetManyTagged ¶
ForgetManyTagged removes a canonical batch atomically under one current tag snapshot.
func (*Backend) ForgetTagged ¶
ForgetTagged removes the stored entry under a current snapshot and reports whether its value was current.
func (*Backend) FoundryAdapter ¶
func (*Backend) FoundryAdapter(frameworkadapter.Seal)
FoundryAdapter marks the backend as framework-owned adapter I/O.
func (*Backend) Get ¶
Get returns an owned copy of a live entry and lazily reclaims expired storage.
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) GetTagged ¶
GetTagged returns owned bytes under a current snapshot and reclaims obsolete entries.
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 (b *Backend) IncrementTagged(ctx context.Context, key cache.TaggedKey, delta int64, ttl cache.TTL) (int64, error)
IncrementTagged atomically increments the counter under a current tag snapshot, preserving an existing expiry.
func (*Backend) InvalidateTags ¶
InvalidateTags atomically replaces the selected metadata with fresh random versions.
func (*Backend) Put ¶
Put copies and replaces the entry and TTL, evicting entries when capacity requires it.
func (*Backend) PutTagged ¶
func (b *Backend) PutTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) error
PutTagged copies and replaces an entry under a current tag snapshot.
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
DefaultConfig returns limits of 10,000 entries and 64 MiB of key and payload bytes.