store

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package store provides a generic data store interface and in-process synchronization primitives. IStore[D] places a pure data structure somewhere (memory, file, or database) and handles synchronization. The data structure itself has no locks or I/O; synchronization is the store's job.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IStore

type IStore[D any] interface {
	// Load reads the current state.
	Load(ctx context.Context) (D, error)

	// Save writes state. The store owns synchronization; the caller does not
	// need to hold external locks.
	Save(ctx context.Context, data D) error
}

IStore[D] is a generic store that places a data structure D somewhere and provides synchronized access. The backend determines the tier (in_process, kernel_io, host, network).

type MemoryStore

type MemoryStore[D any] struct {
	// contains filtered or unexported fields
}

MemoryStore[D] is an in-process, synchronized store that holds one value in memory. It is safe for concurrent access. The caller is responsible for cloning D on load if mutation isolation is required; the store itself performs no copying.

CS-5 justification: The mutex is an honest leaf critical section guarding one store value. No coordinate state, no nested locks, no waiting on other components. Caller serializes all access through Load/Save methods.

func NewMemoryStore

func NewMemoryStore[D any]() *MemoryStore[D]

NewMemoryStore creates a new empty in-process store.

func (*MemoryStore[D]) Load

func (s *MemoryStore[D]) Load(ctx context.Context) (D, error)

Load returns a copy of the current state. If no value has been saved, it returns the zero value of D.

func (*MemoryStore[D]) Save

func (s *MemoryStore[D]) Save(ctx context.Context, data D) error

Save atomically writes the value to the store. Concurrent loads see the new value after the call returns.

func (*MemoryStore[D]) Saved

func (s *MemoryStore[D]) Saved() bool

Saved reports whether Save has been called at least once.

Jump to

Keyboard shortcuts

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