Documentation
¶
Overview ¶
Package idempotent provides a SQLite-backed idempotency guard. It stores a SHA-256 hash of the caller-provided key and the result of the first execution. Subsequent calls with the same key return the cached result without re-executing the function.
Index ¶
- Constants
- type Guard
- func (g *Guard) Count(ctx context.Context) (int64, error)
- func (g *Guard) Delete(ctx context.Context, key string) error
- func (g *Guard) Init() error
- func (g *Guard) Once(ctx context.Context, key string, fn func() ([]byte, error)) ([]byte, error)
- func (g *Guard) Prune(ctx context.Context, olderThan time.Duration) (int64, error)
- func (g *Guard) Seen(ctx context.Context, key string) (bool, error)
Constants ¶
const Schema = `` /* 278-byte string literal not displayed */
Schema creates the idempotent_log table.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard provides idempotent execution backed by SQLite.
func (*Guard) Once ¶
Once executes fn only if key has not been seen before. If key was already processed, returns the cached result. The key is hashed with SHA-256 before storage.
If fn returns an error, the error message is stored and returned on subsequent calls (the function is NOT retried).