memstore

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package memstore provides an in-memory checkpoint.Store for tests and single-process demos. CAS tokens are minted from a per-store monotonic counter, and Save/Load hand back deep copies so stored envelopes are safe against caller mutation.

State does not survive a process restart; use jsonlstore for local durability. Conformance with the Store contract is asserted by the shared storetest suite.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is an in-memory checkpoint.Store. The zero value is not usable; call New. It is safe for concurrent use.

func New

func New() *Store

New returns an empty in-memory Store.

Example

ExampleNew demonstrates the Save/Load/Delete round-trip and the claim-once CAS semantics of the in-memory store.

package main

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"

	"chainguard.dev/driftlessaf/agents/checkpoint"
	"chainguard.dev/driftlessaf/agents/checkpoint/memstore"
)

func main() {
	ctx := context.Background()
	store := memstore.New()

	env := &checkpoint.Envelope{
		Version:       checkpoint.EnvelopeVersion,
		Provider:      checkpoint.ProviderAnthropic,
		ReconcilerKey: "org/repo#42",
		RunID:         "run-1",
		ProviderState: json.RawMessage(`{"model":"claude-fable-5"}`),
	}
	if err := store.Save(ctx, env.ReconcilerKey, env); err != nil {
		fmt.Println("error:", err)
		return
	}

	loaded, tok, ok, err := store.Load(ctx, env.ReconcilerKey)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println("parked:", ok, loaded.RunID)

	// Delete with the Load token claims the envelope exactly once; a stale
	// token loses with ErrTokenMismatch.
	fmt.Println("claimed:", store.Delete(ctx, env.ReconcilerKey, tok))
	fmt.Println("stale claim:",
		errors.Is(store.Delete(ctx, env.ReconcilerKey, tok), checkpoint.ErrTokenMismatch))
}
Output:
parked: true run-1
claimed: <nil>
stale claim: true

func (*Store) Delete

func (s *Store) Delete(_ context.Context, key string, tok checkpoint.Token) error

Delete removes key only if tok matches the current generation.

func (*Store) Load

Load returns a deep copy of the stored envelope and its CAS token.

func (*Store) Save

func (s *Store) Save(_ context.Context, key string, env *checkpoint.Envelope) error

Save writes a deep copy of env under key and advances the CAS generation.

Jump to

Keyboard shortcuts

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