cache

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cache provides Gombit's backend-neutral cache boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisClient

func NewRedisClient(cfg config.RedisConfig) (*redis.Client, error)

NewRedisClient builds a go-redis client from typed configuration.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string, dst any) (bool, error)
	Set(ctx context.Context, key string, value any, ttl time.Duration) error
	Delete(ctx context.Context, keys ...string) error
	Increment(ctx context.Context, key string, delta int64) (int64, error)
}

Cache is the value-oriented cache contract used by framework features.

func Namespace

func Namespace(namespace string, next Cache) Cache

Namespace prefixes all keys before forwarding operations to next.

type Driver

type Driver string

Driver names an opened cache driver.

const (
	// DriverMemory stores cache values in process memory.
	DriverMemory Driver = Driver(config.CacheDriverMemory)
	// DriverRedis stores cache values in Redis.
	DriverRedis Driver = Driver(config.CacheDriverRedis)
	// DriverNoop disables persistence while preserving cache call sites.
	DriverNoop Driver = Driver(config.CacheDriverNoop)
)

type Memory

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

Memory stores cache values in process memory.

func NewMemory

func NewMemory() *Memory

NewMemory creates an empty in-process cache.

func (*Memory) Delete

func (m *Memory) Delete(ctx context.Context, keys ...string) error

Delete implements Cache.

func (*Memory) Get

func (m *Memory) Get(ctx context.Context, key string, dst any) (bool, error)

Get implements Cache.

func (*Memory) Increment

func (m *Memory) Increment(ctx context.Context, key string, delta int64) (int64, error)

Increment implements Cache.

func (*Memory) Set

func (m *Memory) Set(ctx context.Context, key string, value any, ttl time.Duration) error

Set implements Cache.

type Noop

type Noop struct{}

Noop disables persistence while preserving cache call sites.

func (Noop) Delete

func (Noop) Delete(ctx context.Context, keys ...string) error

Delete implements Cache.

func (Noop) Get

func (Noop) Get(ctx context.Context, key string, dst any) (bool, error)

Get implements Cache.

func (Noop) Increment

func (Noop) Increment(ctx context.Context, key string, delta int64) (int64, error)

Increment implements Cache.

func (Noop) Set

func (Noop) Set(ctx context.Context, key string, value any, ttl time.Duration) error

Set implements Cache.

type Redis

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

Redis stores cache values in Redis.

func NewRedis

func NewRedis(client *redis.Client) *Redis

NewRedis wraps a go-redis client with Gombit's cache contract.

func (*Redis) Client

func (r *Redis) Client() *redis.Client

Client returns the underlying go-redis client.

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, keys ...string) error

Delete implements Cache.

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string, dst any) (bool, error)

Get implements Cache.

func (*Redis) Increment

func (r *Redis) Increment(ctx context.Context, key string, delta int64) (int64, error)

Increment implements Cache.

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, value any, ttl time.Duration) error

Set implements Cache.

type Store

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

Store is an opened cache with driver metadata and optional Redis escape hatch.

func Open

func Open(cfg config.CacheConfig) (*Store, error)

Open opens the configured cache driver.

func (*Store) Close

func (s *Store) Close() error

Close closes driver-owned resources.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, keys ...string) error

Delete implements Cache.

func (*Store) Driver

func (s *Store) Driver() Driver

Driver returns the configured driver.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, dst any) (bool, error)

Get implements Cache.

func (*Store) Increment

func (s *Store) Increment(ctx context.Context, key string, delta int64) (int64, error)

Increment implements Cache.

func (*Store) Redis

func (s *Store) Redis() *redis.Client

Redis returns the underlying go-redis client when the Redis driver is enabled.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value any, ttl time.Duration) error

Set implements Cache.

Jump to

Keyboard shortcuts

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