memory

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package memory stores and fetches context blobs by content address. Put computes the sha256: ref with envelope.ContextRef and returns it. Get fetches a blob by that ref. A size budget bounds the store; a Put that would exceed the budget evicts the oldest-inserted blobs first.

Map: store.go = Store, New, Put, Get, and the sentinel errors ErrNoBudget, ErrBudgetExceeded, ErrUnknownRef. Memory holds opaque bytes; it does not parse or validate the content, and it does not know about envelope.Message or any other wire type. Rationale: ../docs/plans/memory.md. Contribution rules: ../AGENTS.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoBudget is the sentinel for a non-positive maxBytes passed
	// to New.
	ErrNoBudget = errors.New("memory: maxBytes must be positive")
	// ErrBudgetExceeded is the sentinel for a blob that Put rejects
	// because it is larger than the store's budget.
	ErrBudgetExceeded = errors.New("memory: content exceeds store budget")
	// ErrUnknownRef is the sentinel for a ref that Get does not hold.
	ErrUnknownRef = errors.New("memory: unknown ref")
)

Sentinel errors for Store operations; test with errors.Is.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds content-addressed blobs under a fixed byte budget. Mutex-guarded, safe for concurrent use. The zero value is not usable; create a Store with New. A Put that would exceed the budget evicts the oldest-inserted blobs, in insertion order, until the new blob fits.

func New

func New(maxBytes int) (*Store, error)

New creates a Store with a fixed byte budget. A non-positive maxBytes wraps ErrNoBudget.

func (*Store) Get

func (s *Store) Get(ref string) ([]byte, error)

Get returns a copy of the blob stored under ref. An unknown ref wraps ErrUnknownRef. Get does not change insertion order.

func (*Store) Put

func (s *Store) Put(content []byte) (ref string, err error)

Put computes ref as envelope.ContextRef(string(content)) and stores content under it. A content whose length exceeds the store's budget wraps ErrBudgetExceeded and stores nothing. A content that fits evicts the oldest-inserted blobs, in insertion order, until the new blob fits within the budget, then stores it. Putting a content whose ref already exists overwrites the stored bytes and refreshes its insertion order to most-recent.

Jump to

Keyboard shortcuts

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