cache

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")

ErrCacheMiss is returned when a key is not found in the cache

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves a value from the cache
	Get(ctx context.Context, key string) ([]byte, error)

	// Set stores a value in the cache with optional expiration
	// If ttl is 0, the value will not be cached
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

	// Close releases any resources used by the cache
	Close() error
}

Cache defines the interface for caching data

type MemoryCache added in v1.2.0

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

MemoryCache implements the Cache interface using RAM

func NewMemoryClient added in v1.2.0

func NewMemoryClient() *MemoryCache

NewMemoryClient creates a new cache client

func (*MemoryCache) Close added in v1.2.0

func (c *MemoryCache) Close() error

Close releases the memory

func (*MemoryCache) Get added in v1.2.0

func (c *MemoryCache) Get(_ context.Context, key string) ([]byte, error)

Get retrieves a value from memory

func (*MemoryCache) Set added in v1.2.0

func (c *MemoryCache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value in memory with the specified TTL If ttl is 0, the value will not be cached

type RedisCache

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

RedisCache implements the Cache interface using Redis

func NewRedisClient

func NewRedisClient(ctx context.Context, addr string) (*RedisCache, error)

NewRedisClient creates a new Redis client

func (*RedisCache) Close

func (c *RedisCache) Close() error

Close releases the Redis client

func (*RedisCache) Get

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

Get retrieves a value from Redis

func (*RedisCache) Set

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

Set stores a value in Redis with the specified TTL If ttl is 0, the value will not be cached

Jump to

Keyboard shortcuts

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