Documentation
¶
Overview ¶
Package stores provides cache implementations for Nexus.
Package stores provides cache store implementations for Nexus.
Index ¶
- type MemoryCache
- func (c *MemoryCache) Clear(_ context.Context) error
- func (c *MemoryCache) Delete(_ context.Context, key string) error
- func (c *MemoryCache) Get(_ context.Context, key string) (*provider.CompletionResponse, error)
- func (*MemoryCache) Kind() string
- func (c *MemoryCache) Set(_ context.Context, key string, resp *provider.CompletionResponse) error
- type MemoryOption
- type MemoryStreamCache
- func (c *MemoryStreamCache) DeleteStream(_ context.Context, key string) error
- func (c *MemoryStreamCache) GetStream(_ context.Context, key string) ([]cache.StreamFrame, error)
- func (*MemoryStreamCache) Kind() string
- func (c *MemoryStreamCache) SetStream(_ context.Context, key string, frames []cache.StreamFrame, ttl time.Duration) error
- type MemoryStreamOption
- type RedisCache
- func (c *RedisCache) Clear(_ context.Context) error
- func (c *RedisCache) Delete(ctx context.Context, key string) error
- func (c *RedisCache) Get(ctx context.Context, key string) (*provider.CompletionResponse, error)
- func (*RedisCache) Kind() string
- func (c *RedisCache) Set(ctx context.Context, key string, resp *provider.CompletionResponse) error
- type RedisClient
- type RedisOption
- type RedisResult
- type RedisStreamCache
- func (c *RedisStreamCache) DeleteStream(ctx context.Context, key string) error
- func (c *RedisStreamCache) GetStream(ctx context.Context, key string) ([]cache.StreamFrame, error)
- func (*RedisStreamCache) Kind() string
- func (c *RedisStreamCache) SetStream(ctx context.Context, key string, frames []cache.StreamFrame, ttl time.Duration) error
- type RedisStreamOption
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) Get ¶
func (c *MemoryCache) Get(_ context.Context, key string) (*provider.CompletionResponse, error)
func (*MemoryCache) Kind ¶
func (*MemoryCache) Kind() string
Kind identifies the backend without contacting it.
func (*MemoryCache) Set ¶
func (c *MemoryCache) Set(_ context.Context, key string, resp *provider.CompletionResponse) error
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.
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 ¶
func (c *RedisCache) Get(ctx context.Context, key string) (*provider.CompletionResponse, error)
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 ¶
func (c *RedisCache) Set(ctx context.Context, key string, resp *provider.CompletionResponse) error
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 ¶
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.
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:").