memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package memory implements deterministic, process-local idempotency storage. It is intended for tests and single-process tooling, not durable coordination.

Index

Constants

View Source
const (
	// DefaultMaxRecords is the process-local record capacity used when omitted.
	DefaultMaxRecords = 10_000
	// MaxRecordCapacity bounds configured process-local record allocation.
	MaxRecordCapacity = 1_000_000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock deprecated

type Clock interface {
	clockpkg.Clock
}

Clock supplies authoritative time to the deterministic memory store.

Deprecated: depend on clock.Clock in new code. This named compatibility contract remains available throughout v1.

type Options

type Options struct {
	// Clock supplies time for every lease and transition decision.
	Clock Clock
	// OwnerTokens returns a unique token for each ownership attempt.
	OwnerTokens func() (string, error)
	// MaxRecords bounds retained records. Zero selects DefaultMaxRecords.
	MaxRecords int
}

Options configures deterministic time and ownership-token generation.

type Store

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

Store keeps idempotency records in process memory under one mutex.

func New

func New(options Options) (*Store, error)

New validates options and constructs an empty process-local store.

func (*Store) Acquire

Acquire atomically elects an owner or returns the retained semantic outcome.

func (*Store) Complete

func (s *Store) Complete(ctx context.Context, request idempotency.CompleteRequest) (idempotency.Record, error)

Complete records a bounded successful result for a live current owner.

func (*Store) Expire

func (s *Store) Expire(ctx context.Context, key idempotency.Key) (idempotency.Record, error)

Expire records that an active lease elapsed according to the injected clock.

func (*Store) Fail

Fail records a bounded terminal failure for a live current owner.

func (*Store) Heartbeat

func (s *Store) Heartbeat(ctx context.Context, request idempotency.HeartbeatRequest) (idempotency.Record, error)

Heartbeat extends a live current owner's lease using the injected clock.

func (*Store) Inspect

func (s *Store) Inspect(ctx context.Context, key idempotency.Key) (idempotency.Record, error)

Inspect returns a copy of the retained record for key.

func (*Store) Release

func (s *Store) Release(ctx context.Context, ownership idempotency.Ownership) (idempotency.Record, error)

Release abandons a live current owner's attempt.

Jump to

Keyboard shortcuts

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