cache

package
v0.0.0-...-9afb6c3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch[T any](cache Cacher, key string, expiration time.Duration, fn func() (T, error)) (T, error)

func FetchArg

func FetchArg[T any, A any](
	cache Cacher,
	key string,
	expiration time.Duration,
	fn func(a A) (T, error), a A) (T, error)

func Key

func Key(args ...interface{}) string

Types

type Cacher

type Cacher interface {
	Get(key string, value interface{}) error
	Set(key string, value interface{}, expiration time.Duration) error
	Delete(keys ...string) error
}

func NewCache

func NewCache(ctx context.Context, conf *config.CacheConfig) Cacher

type MemoryCache

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

func NewMemoryCache

func NewMemoryCache(size int) *MemoryCache

func (*MemoryCache) Delete

func (m *MemoryCache) Delete(keys ...string) error

func (*MemoryCache) Get

func (m *MemoryCache) Get(key string, value interface{}) error

func (*MemoryCache) Set

func (m *MemoryCache) Set(key string, value interface{}, expiration time.Duration) error

type RedisCache

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

func NewRedisCache

func NewRedisCache(ctx context.Context, client *redis.Client) *RedisCache

func (*RedisCache) Delete

func (r *RedisCache) Delete(keys ...string) error

func (*RedisCache) Get

func (r *RedisCache) Get(key string, value interface{}) error

func (*RedisCache) Set

func (r *RedisCache) Set(key string, value interface{}, expiration time.Duration) error

Jump to

Keyboard shortcuts

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