cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAll

func CloseAll() error

CloseAll closes all Redis connections

func CloseConnection

func CloseConnection(name string) error

CloseConnection safely closes and removes a specific connection

func GetClient

func GetClient(name string) (*redis.Client, bool)

GetClient returns a specific Redis client by name

func GetConnection

func GetConnection(name string, cfg *config.RedisConfig) (*redis.Client, error)

GetConnection returns a cached Redis connection or creates a new one

func ListConnections

func ListConnections() []string

ListConnections returns all connection names

func Ready

func Ready(name string) bool

Ready checks if a specific Redis connection is alive

Types

type IdempotencyRecord

type IdempotencyRecord struct {
	Key         string    `json:"key"`
	Response    []byte    `json:"response"`
	ContentType string    `json:"content_type"`
	StatusCode  int       `json:"status_code"`
	CreatedAt   time.Time `json:"created_at"`
}

IdempotencyRecord stores the cached response for an idempotent request

type IdempotencyStore

type IdempotencyStore interface {
	// Get retrieves a cached response by idempotency key
	// Returns nil, nil if key does not exist
	Get(ctx context.Context, key string) (*IdempotencyRecord, error)

	// Store saves a response with the given idempotency key and TTL
	Store(ctx context.Context, key string, record *IdempotencyRecord, ttl time.Duration) error

	// Exists checks if an idempotency key exists (for quick checks)
	Exists(ctx context.Context, key string) (bool, error)

	// Delete removes an idempotency record
	Delete(ctx context.Context, key string) error
}

IdempotencyStore interface for storing/retrieving idempotency records

type RedisIdempotencyStore

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

RedisIdempotencyStore implements IdempotencyStore using Redis

func NewRedisIdempotencyStore

func NewRedisIdempotencyStore(client *redis.Client, prefix string) *RedisIdempotencyStore

NewRedisIdempotencyStore creates a new Redis-backed idempotency store prefix: namespace for keys (e.g., "idempotency" -> "idempotency:key")

func (*RedisIdempotencyStore) Delete

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

Delete removes an idempotency record

func (*RedisIdempotencyStore) Exists

func (s *RedisIdempotencyStore) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an idempotency key exists (for quick checks without fetching data)

func (*RedisIdempotencyStore) Get

Get retrieves a cached response by idempotency key Returns nil, nil if key does not exist (not an error condition)

func (*RedisIdempotencyStore) Store

Store saves a response with the given idempotency key and TTL

Jump to

Keyboard shortcuts

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