Documentation
¶
Overview ¶
Package idempotency provides a contrib in-memory idempotency store.
The memory store is useful for local development, tests, and examples. It is not a durable production store; production APIs should use storage with shared process visibility and retention aligned with retry windows.
Index ¶
- type LegacyInFlightRecoveryEvent
- type LegacyInFlightRecoveryHandler
- type LegacyInFlightRecoveryOutcome
- type MemoryStore
- func (m *MemoryStore) Get(ctx context.Context, key string) (ports.IdempotencyRecord, bool, error)
- func (m *MemoryStore) Release(ctx context.Context, key string) error
- func (m *MemoryStore) ReleaseReservation(ctx context.Context, key, token string) error
- func (m *MemoryStore) Save(ctx context.Context, key string, record ports.IdempotencyRecord, ...) error
- func (m *MemoryStore) TryBegin(ctx context.Context, key string, record ports.IdempotencyRecord, ...) (bool, error)
- type MemoryStoreOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LegacyInFlightRecoveryEvent ¶ added in v2.1.0
type LegacyInFlightRecoveryEvent struct {
// Key is hashed by default. It contains the raw key only when
// MemoryStoreOptions.LegacyInFlightRecoveryRawKey is explicitly enabled.
Key string
// KeyHash always contains the hashed key value when a key is available.
KeyHash string
// RawKey is populated only when LegacyInFlightRecoveryRawKey is explicitly enabled.
RawKey string
Outcome LegacyInFlightRecoveryOutcome
}
LegacyInFlightRecoveryEvent carries structured context for legacy token recovery.
type LegacyInFlightRecoveryHandler ¶ added in v2.1.0
type LegacyInFlightRecoveryHandler func(context.Context, LegacyInFlightRecoveryEvent)
LegacyInFlightRecoveryHandler is invoked when a tokenless legacy recovery branch is encountered. Keep handlers fast and non-blocking.
type LegacyInFlightRecoveryOutcome ¶ added in v2.1.0
type LegacyInFlightRecoveryOutcome string
LegacyInFlightRecoveryOutcome captures whether a legacy tokenless recovery path was exercised in the adapter.
const ( // LegacyInFlightRecoveryRecovered indicates tokenless legacy in-flight state // was intentionally migrated away. LegacyInFlightRecoveryRecovered LegacyInFlightRecoveryOutcome = "legacy_in_flight_recovered" // LegacyInFlightRecoveryTokenMismatch indicates a token was supplied for a // tokenless legacy in-flight record and release was rejected. LegacyInFlightRecoveryTokenMismatch LegacyInFlightRecoveryOutcome = "legacy_in_flight_token_mismatch" )
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory idempotency store intended for development/testing.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore constructs an in-memory idempotency store.
func NewMemoryStoreWithOptions ¶ added in v2.1.0
func NewMemoryStoreWithOptions(opts MemoryStoreOptions) *MemoryStore
NewMemoryStoreWithOptions constructs an in-memory idempotency store with optional observability hooks.
func (*MemoryStore) Get ¶
func (m *MemoryStore) Get(ctx context.Context, key string) (ports.IdempotencyRecord, bool, error)
Get returns an idempotency record if present and not expired.
func (*MemoryStore) Release ¶ added in v2.1.0
func (m *MemoryStore) Release(ctx context.Context, key string) error
Release removes an in-flight idempotency reservation by key.
This method preserves the v2 compatibility contract. New middleware uses ReleaseReservation when available so tokened reservations are not released by unrelated requests.
func (*MemoryStore) ReleaseReservation ¶ added in v2.1.0
func (m *MemoryStore) ReleaseReservation(ctx context.Context, key, token string) error
ReleaseReservation removes a stored idempotency reservation when token matches.
type MemoryStoreOptions ¶ added in v2.1.0
type MemoryStoreOptions struct {
OnLegacyInFlightRecovery LegacyInFlightRecoveryHandler
// LegacyInFlightRecoveryRawKey exposes raw idempotency keys in recovery events.
// Defaults to false so adapter telemetry receives hashed keys.
LegacyInFlightRecoveryRawKey bool
}
MemoryStoreOptions configures legacy recovery telemetry for memory store usage.