cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hooks

type Hooks struct {
	OnHit    func(ctx context.Context, key string)
	OnMiss   func(ctx context.Context, key string)
	OnSet    func(ctx context.Context, key string, ttl time.Duration)
	OnDelete func(ctx context.Context, key string)
	OnError  func(ctx context.Context, op string, key string, err error)
}

Hooks defines cache lifecycle callbacks.

type RedisOptions

type RedisOptions struct {
	DisableDefaults bool
	Network         string
	Address         string
	Username        string
	Password        string
	DB              int
	Prefix          string
	DefaultTTL      time.Duration
	DialTimeout     time.Duration
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration
}

RedisOptions configures a Redis cache store.

type RedisStore

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

RedisStore stores cache entries in Redis.

func NewRedisStore

func NewRedisStore(options RedisOptions) *RedisStore

NewRedisStore creates a Redis-backed cache store.

func (*RedisStore) Delete

func (s *RedisStore) Delete(ctx context.Context, key string) error

Delete removes a cache entry.

func (*RedisStore) Get

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

Get returns a cache entry by key.

func (*RedisStore) Set

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

Set stores a cache entry with an optional TTL.

type Store

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

Store defines cache operations.

func WithHooks

func WithHooks(store Store, hooks Hooks) Store

WithHooks wraps a store with hook callbacks.

Jump to

Keyboard shortcuts

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