store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store holds context-guru's cross-call state behind one interface so both hosts (bifrost proxy, AuthBridge plugin) share it. v1 ships an in-memory TTL+LRU backend; SQLite/Redis slot in behind the same interface when a durable or multi-replica deployment is real (see the design doc, D5).

It carries three things keyed by session:

  • Rewind: cache_key -> original bytes, so Offload components are reversible (the expand(id) tool loop resolves originals from here).
  • Sticky: the set of content ids already reduced on prior turns, so a component can keep its output byte-stable across turns (cache stability).
  • per-session token/metric rollups (added with metrics in P0/P5).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

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

Memory is an in-memory Store: a TTL+LRU cache for rewind payloads plus a bounded per-session sticky-id set. Defaults mirror headroom's CCR store (1800s TTL, 1000 entries).

func NewMemory

func NewMemory(o Options) *Memory

NewMemory builds an in-memory store. Zero/negative option fields fall back to defaults (1800s TTL, 1000 entries, 100 sessions of sticky sets).

func (*Memory) Get

func (m *Memory) Get(key string) ([]byte, bool)

func (*Memory) MarkSticky

func (m *Memory) MarkSticky(session, id string)

func (*Memory) Persists

func (*Memory) Persists() bool

func (*Memory) Put

func (m *Memory) Put(key string, payload []byte)

func (*Memory) Sticky

func (m *Memory) Sticky(session string) map[string]struct{}

type Nop

type Nop struct{}

Nop is a Store that persists nothing: Put discards, Get/Sticky always miss. Used when the store is disabled — the expand loop resolves nothing and lossy offloads become irreversible, which is why they must use marker_mode: off.

func (Nop) Get

func (Nop) Get(string) ([]byte, bool)

func (Nop) MarkSticky

func (Nop) MarkSticky(string, string)

func (Nop) Persists

func (Nop) Persists() bool

func (Nop) Put

func (Nop) Put(string, []byte)

func (Nop) Sticky

func (Nop) Sticky(string) map[string]struct{}

type Options

type Options struct {
	// Enabled toggles the state store. nil/absent => on (backward-compatible).
	// false => no store: reversibility is off, so offload components must run
	// marker_mode: off (a full-marker offload would leave dangling markers).
	Enabled     *bool `yaml:"enabled"`
	TTLSeconds  int   `yaml:"ttl_seconds"`
	MaxEntries  int   `yaml:"max_entries"`
	MaxSessions int   `yaml:"max_sessions"`
}

Options configures a Memory store; the zero value yields sane defaults. yaml tags let it drop straight into the config file's store: block.

type Store

type Store interface {
	// Put stashes an original payload under key with the store's default TTL.
	Put(key string, payload []byte)
	// Get returns a stashed payload; ok=false if absent or expired.
	Get(key string) (payload []byte, ok bool)
	// Sticky returns the per-session set of already-reduced content ids.
	Sticky(session string) map[string]struct{}
	// MarkSticky records that id was reduced in this session.
	MarkSticky(session, id string)
	// Persists reports whether Put actually retains payloads. false (the Nop
	// store) means offloads cannot be made reversible, so a full marker_mode must
	// degrade to an irreversible drop rather than leave an unresolvable marker.
	Persists() bool
}

Store is the interface components and adapters depend on. Implementations must be safe for concurrent use — one instance serves all requests.

Jump to

Keyboard shortcuts

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