cache

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides a generic key-value store abstraction. Concrete backends (Redis, in-memory) implement the Store interface. Domain-specific caches (model cache, response cache) build on top of Store.

Index

Constants

View Source
const (
	DefaultRedisTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MapStore

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

MapStore is an in-memory Store for testing.

func NewMapStore

func NewMapStore() *MapStore

NewMapStore creates an in-memory store.

func (*MapStore) Close

func (s *MapStore) Close() error

Close is a no-op.

func (*MapStore) Get

func (s *MapStore) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves value by key.

func (*MapStore) Set

func (s *MapStore) Set(ctx context.Context, key string, value []byte, _ time.Duration) error

Set stores value. TTL is ignored.

type Pinger

type Pinger interface {
	Ping(ctx context.Context) error
}

Pinger is an optional capability for stores backed by a network service that can verify connectivity. Network-backed stores (RedisStore) implement it; in-memory stores (MapStore) do not, since they are always reachable.

type RedisStore

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

RedisStore implements generic key-value storage. Used by response cache.

func NewRedisStore

func NewRedisStore(cfg RedisStoreConfig) (*RedisStore, error)

NewRedisStore creates a Redis-based key-value store.

func (*RedisStore) Close

func (s *RedisStore) Close() error

Close closes the Redis connection.

func (*RedisStore) Get

func (s *RedisStore) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves value by key.

func (*RedisStore) Ping

func (s *RedisStore) Ping(ctx context.Context) error

Ping verifies connectivity to Redis.

func (*RedisStore) Set

func (s *RedisStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores value with TTL.

type RedisStoreConfig

type RedisStoreConfig struct {
	URL    string
	Prefix string
	TTL    time.Duration
}

RedisStoreConfig holds configuration for generic Redis key-value store.

type Store

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

Store is a generic key-value store. RedisStore and MapStore implement it.

Directories

Path Synopsis
Package modelcache provides model-specific cache types and interfaces.
Package modelcache provides model-specific cache types and interfaces.

Jump to

Keyboard shortcuts

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