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 ¶
- type Cache
- func (c *Cache) Apply(_ context.Context, _ storage.Tx, e eventstore.Event) error
- func (c *Cache) Discard()
- func (c *Cache) Get(id EntityID) (State, bool)
- func (c *Cache) Len() int
- func (c *Cache) Name() string
- func (c *Cache) Promote()
- func (c *Cache) Restore(ctx context.Context, tx storage.Tx) (uint64, error)
- func (c *Cache) Snapshot(ctx context.Context, tx storage.Tx) error
- func (c *Cache) View() *immutable.Map[EntityID, State]
- type EntityID
- type State
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 (*Cache) Apply ¶
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) Promote ¶
func (c *Cache) Promote()
Promote swaps the pending HAMT into current. Called by the store after the Append transaction commits.
func (*Cache) Restore ¶
Restore reads the latest snapshot for this cache from the snapshots table and populates the current map. Returns the snapshot position (0 if none).