memory

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package memory supplies a bounded, concurrency-safe cache backend for local development and deterministic tests. It does not provide distributed guarantees.

Index

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 New

func New(config Config, source clock.Clock) (*Backend, error)

func (*Backend) Add

func (b *Backend) Add(ctx context.Context, key cache.EntryKey, data []byte, ttl cache.TTL) (bool, error)

func (*Backend) AddTagged

func (b *Backend) AddTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) (bool, error)

func (*Backend) Close

func (b *Backend) Close(ctx context.Context) error

func (*Backend) Exists

func (b *Backend) Exists(ctx context.Context, key cache.EntryKey) (bool, error)

func (*Backend) ExistsTagged

func (b *Backend) ExistsTagged(ctx context.Context, key cache.TaggedKey) (bool, error)

func (*Backend) Expire

func (b *Backend) Expire(ctx context.Context, key cache.EntryKey, ttl cache.TTL) (bool, error)

func (*Backend) ExpireTagged

func (b *Backend) ExpireTagged(ctx context.Context, key cache.TaggedKey, ttl cache.TTL) (bool, error)

func (*Backend) Forget

func (b *Backend) Forget(ctx context.Context, key cache.EntryKey) (bool, error)

func (*Backend) ForgetMany

func (b *Backend) ForgetMany(ctx context.Context, keys []cache.EntryKey) (uint64, error)

func (*Backend) ForgetManyTagged

func (b *Backend) ForgetManyTagged(ctx context.Context, keys []cache.TaggedKey) (uint64, error)

func (*Backend) ForgetTagged

func (b *Backend) ForgetTagged(ctx context.Context, key cache.TaggedKey) (bool, error)

func (*Backend) FoundryAdapter

func (*Backend) FoundryAdapter(frameworkadapter.Seal)

FoundryAdapter marks the backend as framework-owned adapter I/O.

func (*Backend) Get

func (b *Backend) Get(ctx context.Context, key cache.EntryKey) ([]byte, bool, error)

func (*Backend) GetMany

func (b *Backend) GetMany(ctx context.Context, keys []cache.EntryKey) ([]cache.BatchValue, error)

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

func (b *Backend) GetTagged(ctx context.Context, key cache.TaggedKey) ([]byte, bool, error)

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)

func (*Backend) InvalidateTags

func (b *Backend) InvalidateTags(ctx context.Context, keys []cache.EntryKey) error

func (*Backend) Put

func (b *Backend) Put(ctx context.Context, key cache.EntryKey, data []byte, ttl cache.TTL) error

func (*Backend) PutTagged

func (b *Backend) PutTagged(ctx context.Context, key cache.TaggedKey, data []byte, ttl cache.TTL) error

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.

func (*Backend) Stats

func (b *Backend) Stats() Stats

type Config

type Config struct {
	MaxEntries int
	MaxBytes   int
}

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

func (Config) Validate

func (c Config) Validate() error

type Stats

type Stats struct {
	Entries   int
	Bytes     int
	Evictions uint64
	Closed    bool
}

Stats reports live entries after lazy expiry collection. Bytes includes keys and payloads; it is not a measurement of total process memory.

Jump to

Keyboard shortcuts

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