Documentation
¶
Overview ¶
Package idempotency provides command deduplication for the dashboard contract: a Store interface plus an in-memory implementation. Wrappers around dispatcher.Dispatch consult the store before invoking command handlers and return cached envelopes when the (key, identity) tuple matches a recent invocation.
Index ¶
Constants ¶
const DefaultMaxEntries = 10000
DefaultMaxEntries is the default LRU cap for an in-memory store.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cached ¶
type Cached struct {
// Status is the HTTP status the original handler returned.
Status int
// WireBody is the JSON envelope the original handler produced, ready to
// write back verbatim.
WireBody json.RawMessage
// StoredAt is when this entry landed in the store.
StoredAt time.Time
// TTL is how long the entry is considered fresh.
TTL time.Duration
}
Cached is one cached command response.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore is a process-local Store with TTL and LRU eviction. Safe for concurrent use.
func NewInMemoryStore ¶
func NewInMemoryStore(opts ...Option) *InMemoryStore
NewInMemoryStore returns an in-memory Store with the given options.
type Option ¶
type Option func(*InMemoryStore)
Option configures an InMemoryStore.
func WithMaxEntries ¶
WithMaxEntries caps the number of cached entries; oldest are evicted first.
type Store ¶
type Store interface {
Lookup(ctx context.Context, key, identity string) (*Cached, bool)
Store(ctx context.Context, key, identity string, c Cached) error
}
Store deduplicates command invocations by (key, identity) tuple. Lookup returns a cached envelope if one is present and unexpired; the dispatcher writes back the cached envelope verbatim when found. Implementations MUST be safe for concurrent use.