stores

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package stores provides cache implementations for Nexus.

Package stores provides cache store implementations for Nexus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryCache

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

MemoryCache is an in-memory LRU cache with TTL support.

func NewMemory

func NewMemory(opts ...MemoryOption) *MemoryCache

NewMemory creates an in-memory LRU cache.

func (*MemoryCache) Clear

func (c *MemoryCache) Clear(_ context.Context) error

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(_ context.Context, key string) error

func (*MemoryCache) Get

func (*MemoryCache) Kind

func (*MemoryCache) Kind() string

Kind identifies the backend without contacting it.

func (*MemoryCache) Set

type MemoryOption

type MemoryOption func(*MemoryCache)

MemoryOption configures the memory cache.

func WithMaxSize

func WithMaxSize(size int) MemoryOption

WithMaxSize sets the maximum number of entries.

func WithTTL

func WithTTL(ttl time.Duration) MemoryOption

WithTTL sets the time-to-live for cache entries.

type MemoryStreamCache

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

MemoryStreamCache is an in-memory store for cached streamed responses. It uses a simple map with TTL — eviction is lazy on Get, plus a soft max-entry cap on Set.

func NewMemoryStream

func NewMemoryStream(opts ...MemoryStreamOption) *MemoryStreamCache

NewMemoryStream creates a new in-memory stream cache.

func (*MemoryStreamCache) DeleteStream

func (c *MemoryStreamCache) DeleteStream(_ context.Context, key string) error

DeleteStream removes the cached frames for key.

func (*MemoryStreamCache) GetStream

func (c *MemoryStreamCache) GetStream(_ context.Context, key string) ([]cache.StreamFrame, error)

GetStream returns the cached frames for key, or nil if absent/expired.

func (*MemoryStreamCache) Kind

func (*MemoryStreamCache) Kind() string

Kind identifies the backend without contacting it.

func (*MemoryStreamCache) SetStream

func (c *MemoryStreamCache) SetStream(_ context.Context, key string, frames []cache.StreamFrame, ttl time.Duration) error

SetStream stores frames under key with the given TTL. ttl=0 means no expiry (subject only to the soft max-keys cap).

type MemoryStreamOption

type MemoryStreamOption func(*MemoryStreamCache)

MemoryStreamOption configures the memory stream cache.

func WithStreamMaxKeys

func WithStreamMaxKeys(n int) MemoryStreamOption

WithStreamMaxKeys caps the number of cached streams.

type RedisCache

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

RedisCache is a Redis-backed cache implementation. It requires a Redis client to be provided at construction time.

Usage:

import "github.com/redis/go-redis/v9"

rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
cache := stores.NewRedis(rdb)

func NewRedis

func NewRedis(client RedisClient, opts ...RedisOption) *RedisCache

NewRedis creates a Redis-backed cache.

func (*RedisCache) Clear

func (c *RedisCache) Clear(_ context.Context) error

Clear is a no-op — bulk-delete by prefix requires SCAN, which we don't expose on the minimal RedisClient interface. Callers needing Clear can flush the database out-of-band.

func (*RedisCache) Delete

func (c *RedisCache) Delete(ctx context.Context, key string) error

Delete removes a cached entry.

func (*RedisCache) Get

Get retrieves a cached completion response. Returns (nil, nil) on miss.

func (*RedisCache) Kind

func (*RedisCache) Kind() string

Kind identifies the backend without contacting it.

func (*RedisCache) Set

Set stores a completion response under key with the configured TTL.

type RedisClient

type RedisClient interface {
	Get(ctx context.Context, key string) RedisResult
	Set(ctx context.Context, key string, value any, ttl time.Duration) RedisResult
	Del(ctx context.Context, keys ...string) RedisResult
}

RedisClient is the minimal interface required from a Redis client. Compatible with github.com/redis/go-redis/v9.

type RedisOption

type RedisOption func(*RedisCache)

RedisOption configures a Redis cache.

func WithRedisPrefix

func WithRedisPrefix(prefix string) RedisOption

WithRedisPrefix sets a key prefix.

func WithRedisTTL

func WithRedisTTL(ttl time.Duration) RedisOption

WithRedisTTL sets the cache TTL.

type RedisResult

type RedisResult interface {
	Bytes() ([]byte, error)
	Err() error
}

RedisResult is the minimal result interface from a Redis command.

type RedisStreamCache

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

RedisStreamCache stores streamed responses (ordered StreamFrames) under a single Redis key per cache entry. The blob is gob-encoded — fast, type-safe, and handles the multi-modal byte payloads (audio/image) without further escaping.

Compatible with the same RedisClient interface as RedisCache.

func NewRedisStream

func NewRedisStream(client RedisClient, opts ...RedisStreamOption) *RedisStreamCache

NewRedisStream creates a Redis-backed stream cache.

func (*RedisStreamCache) DeleteStream

func (c *RedisStreamCache) DeleteStream(ctx context.Context, key string) error

DeleteStream removes a cached stream.

func (*RedisStreamCache) GetStream

func (c *RedisStreamCache) GetStream(ctx context.Context, key string) ([]cache.StreamFrame, error)

GetStream returns cached frames for key, or nil on miss.

func (*RedisStreamCache) Kind

func (*RedisStreamCache) Kind() string

Kind identifies the backend without contacting it.

func (*RedisStreamCache) SetStream

func (c *RedisStreamCache) SetStream(ctx context.Context, key string, frames []cache.StreamFrame, ttl time.Duration) error

SetStream stores frames under key with the given TTL. ttl=0 means no explicit expiry (server default applies).

type RedisStreamOption

type RedisStreamOption func(*RedisStreamCache)

RedisStreamOption configures the Redis stream cache.

func WithRedisStreamPrefix

func WithRedisStreamPrefix(prefix string) RedisStreamOption

WithRedisStreamPrefix sets a key prefix (default "nexus:stream:").

Jump to

Keyboard shortcuts

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