state

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package state owns the in-memory copy-on-write cache of entity state. The cache is a materialized projection of the event log; the log is the source of truth.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache holds entity state via an immutable HAMT behind atomic.Pointer. The store calls Apply inside an Append transaction to build the next snapshot, then calls Promote after the transaction commits. Reads go through View/Get against the currently promoted snapshot.

func New

func New() *Cache

func (*Cache) Apply

func (c *Cache) Apply(_ context.Context, _ storage.Tx, e eventstore.Event) error

Apply mutates the pending HAMT. Callers MUST call Promote after the enclosing transaction commits (or Discard on rollback).

func (*Cache) Discard

func (c *Cache) Discard()

Discard drops the pending HAMT (used if the transaction rolls back).

func (*Cache) Get

func (c *Cache) Get(id EntityID) (State, bool)

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Name

func (c *Cache) Name() string

Name implements eventstore.Projector.

func (*Cache) Promote

func (c *Cache) Promote()

Promote swaps the pending HAMT into current. Called by the store after the Append transaction commits.

func (*Cache) Restore

func (c *Cache) Restore(ctx context.Context, tx storage.Tx) (uint64, error)

Restore reads the latest snapshot for this cache from the snapshots table and populates the current map. Returns the snapshot position (0 if none).

func (*Cache) Snapshot

func (c *Cache) Snapshot(ctx context.Context, tx storage.Tx) error

Snapshot serialises the current cache state to the snapshots table using protobuf+zstd encoding.

func (*Cache) View

func (c *Cache) View() *immutable.Map[EntityID, State]

type EntityID

type EntityID = string

type State

type State struct {
	EntityID   EntityID
	UpdatedAt  time.Time
	UpdatedBy  string
	Attributes *entityv1.Attributes
}

Jump to

Keyboard shortcuts

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