cache

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: BSD-2-Clause 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 key-value cache contract with in-memory TTL and Redis backends for gRPC middleware caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisStore

func NewRedisStore(addr string) IOE.IOEither[error, Store]

NewRedisStore connects to Redis at addr, verifies reachability with Ping, and returns the initialized Store.

Types

type MemoryStore

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

MemoryStore is an in-memory TTL cache backed by ttlcache/v3.

func (*MemoryStore) Close

func (m *MemoryStore) Close() error

Close clears all entries from the in-memory cache.

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(
	_ context.Context,
	key string,
) IOE.IOEither[error, struct{}]

Delete removes key from the in-memory cache.

func (*MemoryStore) Get

func (m *MemoryStore) Get(
	_ context.Context,
	key string,
) IOE.IOEither[error, O.Option[[]byte]]

Get retrieves the cached byte slice for key, returning O.None when the key is missing or expired.

func (*MemoryStore) Set

func (m *MemoryStore) Set(
	_ context.Context,
	key string,
	val []byte,
	ttl time.Duration,
) IOE.IOEither[error, struct{}]

Set stores a defensive copy of val under key with the given TTL.

type RedisStore

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

RedisStore is a Redis-backed Store implementation using go-redis/v9.

func (*RedisStore) Close

func (r *RedisStore) Close() error

Close closes the underlying Redis client connection.

func (*RedisStore) Delete

func (r *RedisStore) Delete(
	ctx context.Context,
	key string,
) IOE.IOEither[error, struct{}]

Delete removes key from Redis.

func (*RedisStore) Get

func (r *RedisStore) Get(
	ctx context.Context,
	key string,
) IOE.IOEither[error, O.Option[[]byte]]

Get retrieves the byte slice stored at key in Redis, mapping redis.Nil to O.None and propagating transport errors on Left.

func (*RedisStore) Set

func (r *RedisStore) Set(
	ctx context.Context,
	key string,
	val []byte,
	ttl time.Duration,
) IOE.IOEither[error, struct{}]

Set writes val at key in Redis with the given TTL.

type Store

type Store interface {
	Get(ctx context.Context, key string) IOE.IOEither[error, O.Option[[]byte]]
	Set(ctx context.Context, key string, val []byte, ttl time.Duration) IOE.IOEither[error, struct{}]
	Delete(ctx context.Context, key string) IOE.IOEither[error, struct{}]
	Close() error
}

Store defines the functional key-value cache contract for serialized protobuf payloads.

func NewMemoryStore

func NewMemoryStore() Store

NewMemoryStore creates an in-memory TTL cache store with touch-on-hit disabled so entries expire strictly after their configured TTL.

Jump to

Keyboard shortcuts

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