cache

package module
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cache persists idempotency records in Redis or Valkey.

New wraps an application-owned Client with attribute and clock Options. The resulting Store implements core Idempotency persistence and can be passed to its manager. The application owns connection setup, TLS, credentials and client shutdown.

Atomic acquisition

The adapter uses atomic claim and compare-and-swap behavior to reject live records and recover expired claims. A missing or zero execution deadline does not make an otherwise unexpired claim recoverable. ConsistencyError identifies storage failures that prevent the required acquisition guarantees.

Use a shared service for coordination across Lambda environments. This module is optional and does not add Redis dependencies to the core Idempotency module.

For usage and compatibility details, see the user guide.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

Client is implemented by go-redis standalone, Sentinel and cluster clients. The caller configures credentials, TLS, deadlines and retries, and owns Close.

type ConsistencyError

type ConsistencyError struct{ Err error }

func (*ConsistencyError) Error

func (e *ConsistencyError) Error() string

func (*ConsistencyError) Unwrap

func (e *ConsistencyError) Unwrap() error

type Options

type Options struct {
	StatusAttribute, ExpiryAttribute, InProgressExpiryAttribute string
	DataAttribute, ValidationAttribute                          string
	Now                                                         func() time.Time
	// OmitValidationOnSuccess reproduces the pinned TypeScript cache writer's
	// omission. Leave false to retain validation when replaying completed records.
	OmitValidationOnSuccess bool
}

type Store

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

func New

func New(client Client, options Options) (*Store, error)
Example

This example configures a shared store. Actual operations require Redis or Valkey.

package main

import (
	"github.com/rambow-cloud/powertools-lambda-go/idempotency"
	"github.com/rambow-cloud/powertools-lambda-go/idempotency/cache"
	"github.com/redis/go-redis/v9"
)

func main() {
	client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
	defer client.Close()
	store, err := cache.New(client, cache.Options{})
	if err != nil {
		panic(err)
	}
	manager, err := idempotency.New(store, idempotency.Options{
		KeyPrefix: "orders", EventKeyJMESPath: "orderId",
	})
	if err != nil {
		panic(err)
	}
	_ = manager // Reuse the manager and wrap business operations during invocations.
}

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (idempotency.Record, error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, record idempotency.Record, now time.Time) error

func (*Store) Update

func (s *Store) Update(ctx context.Context, record idempotency.Record) error

Jump to

Keyboard shortcuts

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