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