cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cache provides optional Valkey read-through caching (W33-01–02).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IncrStore

type IncrStore interface {
	Store
	// Incr increments key by 1, sets TTL when key is new or on each bump when ttl > 0, returns new value.
	Incr(ctx context.Context, key string, ttl time.Duration) (int64, error)
}

IncrStore optionally supports atomic increment (Valkey INCR / memory mutex). Used for cluster lockout and rate-limit counters (W76 residual).

type MemoryStore

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

MemoryStore is an in-process cache used when Valkey is unavailable.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore constructs an in-memory cache fallback.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(_ context.Context, key string)

func (*MemoryStore) Get

func (s *MemoryStore) Get(_ context.Context, key string) ([]byte, bool)

func (*MemoryStore) Incr

func (s *MemoryStore) Incr(_ context.Context, key string, ttl time.Duration) (int64, error)

Incr implements IncrStore with a process-local mutex.

func (*MemoryStore) Set

func (s *MemoryStore) Set(_ context.Context, key string, value []byte, ttl time.Duration)

type Store

type Store interface {
	Get(ctx context.Context, key string) ([]byte, bool)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration)
	Delete(ctx context.Context, key string)
}

Store abstracts cache get/set/invalidate.

func NewValkeyStore

func NewValkeyStore(url string) Store

NewValkeyStore constructs a cache with optional Valkey backend. URL format: valkey://host:port or host:port. Empty URL uses in-memory cache only.

type ValkeyStore

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

ValkeyStore uses a Valkey-compatible RESP server when URL is set; falls back to memory.

func (*ValkeyStore) Delete

func (v *ValkeyStore) Delete(ctx context.Context, key string)

func (*ValkeyStore) Get

func (v *ValkeyStore) Get(ctx context.Context, key string) ([]byte, bool)

func (*ValkeyStore) Incr

func (v *ValkeyStore) Incr(ctx context.Context, key string, ttl time.Duration) (int64, error)

Incr prefers remote atomic INCR when available, else memory fallback.

func (*ValkeyStore) Set

func (v *ValkeyStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration)

Jump to

Keyboard shortcuts

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