cache

package
v0.0.0-...-79b75f4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTTL = time.Hour
View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type Cache

type Cache[T any] interface {
	Get(ctx context.Context, key string) (T, error)
	Set(ctx context.Context, key string, value T) error
	SetNX(ctx context.Context, key string, value T) (bool, error)
	Exists(ctx context.Context, key string) (bool, error)
	Delete(ctx context.Context, keys ...string) error
}

func NewRedis

func NewRedis[T any](client *redis.Client, serviceName, keyPrefix string, ttl time.Duration) Cache[T]

type MapCache

type MapCache[T any] interface {
	Get(ctx context.Context, key string) (T, error)
	GetAll(ctx context.Context) ([]T, error)
	GetAllMap(ctx context.Context) (map[string]T, error)
	Set(ctx context.Context, key string, value T) error
	SetAll(ctx context.Context, values []T, keyFunc func(v T) string) error
	SetAllMap(ctx context.Context, valuesMap map[string]T) error
	Exists(ctx context.Context, key string) (bool, error)
	Delete(ctx context.Context, keys ...string) error
	DeleteAll(ctx context.Context) error
}

func NewRedisMap

func NewRedisMap[T any](client *redis.Client, serviceName, keyPrefix string, ttl time.Duration) MapCache[T]

type Memory

type Memory[T any] struct {
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory[T any](ttl, cleanInterval time.Duration) *Memory[T]

func (*Memory[T]) Close

func (c *Memory[T]) Close()

func (*Memory[T]) Delete

func (c *Memory[T]) Delete(_ context.Context, keys ...string) error

func (*Memory[T]) DeleteAll

func (c *Memory[T]) DeleteAll(_ context.Context) error

func (*Memory[T]) Exists

func (c *Memory[T]) Exists(_ context.Context, key string) (bool, error)

func (*Memory[T]) Get

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

func (*Memory[T]) GetAll

func (c *Memory[T]) GetAll(_ context.Context) ([]T, error)

func (*Memory[T]) GetAllMap

func (c *Memory[T]) GetAllMap(_ context.Context) (map[string]T, error)

func (*Memory[T]) Set

func (c *Memory[T]) Set(_ context.Context, key string, value T) error

func (*Memory[T]) SetAll

func (c *Memory[T]) SetAll(_ context.Context, values []T, keyFunc func(v T) string) error

func (*Memory[T]) SetAllMap

func (c *Memory[T]) SetAllMap(_ context.Context, valuesMap map[string]T) error

func (*Memory[T]) SetNX

func (c *Memory[T]) SetNX(ctx context.Context, key string, value T) (bool, error)

type Redis

type Redis[T any] struct {
	// contains filtered or unexported fields
}

func (*Redis[T]) Delete

func (c *Redis[T]) Delete(ctx context.Context, keys ...string) error

func (*Redis[T]) Exists

func (c *Redis[T]) Exists(ctx context.Context, key string) (bool, error)

func (*Redis[T]) Get

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

func (*Redis[T]) Set

func (c *Redis[T]) Set(ctx context.Context, key string, value T) error

func (*Redis[T]) SetNX

func (c *Redis[T]) SetNX(ctx context.Context, key string, value T) (bool, error)

type RedisMap

type RedisMap[T any] struct {
	// contains filtered or unexported fields
}

func (*RedisMap[T]) Delete

func (c *RedisMap[T]) Delete(ctx context.Context, keys ...string) error

func (*RedisMap[T]) DeleteAll

func (c *RedisMap[T]) DeleteAll(ctx context.Context) error

func (*RedisMap[T]) Exists

func (c *RedisMap[T]) Exists(ctx context.Context, key string) (bool, error)

func (*RedisMap[T]) Get

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

func (*RedisMap[T]) GetAll

func (c *RedisMap[T]) GetAll(ctx context.Context) ([]T, error)

func (*RedisMap[T]) GetAllMap

func (c *RedisMap[T]) GetAllMap(ctx context.Context) (map[string]T, error)

func (*RedisMap[T]) Set

func (c *RedisMap[T]) Set(ctx context.Context, key string, value T) error

Set not recommended

func (*RedisMap[T]) SetAll

func (c *RedisMap[T]) SetAll(ctx context.Context, values []T, keyFunc func(v T) string) error

func (*RedisMap[T]) SetAllMap

func (c *RedisMap[T]) SetAllMap(ctx context.Context, valuesMap map[string]T) error

Jump to

Keyboard shortcuts

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