cache

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound     = errors.New("cache: key not found")
	ErrCacheMarshal    = errors.New("cache: failed to marshal value")
	ErrCacheUnmarshal  = errors.New("cache: failed to unmarshal value")
	ErrCacheGet        = errors.New("cache: failed to get")
	ErrCacheSet        = errors.New("cache: failed to set")
	ErrCacheTTL        = errors.New("cache: failed to set TTL")
	ErrCacheDelete     = errors.New("cache: failed to delete")
	ErrCacheInvalidate = errors.New("cache: failed to invalidate")
)
View Source
var ErrCacheInvalidKeyType = errors.New("cache: invalid key type")

Functions

This section is empty.

Types

type Cache

type Cache[K any, V any] struct {
	// contains filtered or unexported fields
}

func New

func New[K any, V any](
	client redis.UniversalClient,
	hashKey string,
	ttl time.Duration,
	keyEncoder KeyEncoder,
) *Cache[K, V]

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(ctx context.Context, key K) error

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(ctx context.Context, key K) (*V, error)

func (*Cache[K, V]) Invalidate

func (c *Cache[K, V]) Invalidate(ctx context.Context) error

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(ctx context.Context, key K, value *V) error

type IntKeyEncoder

type IntKeyEncoder struct{}

func NewIntKeyEncoder

func NewIntKeyEncoder() *IntKeyEncoder

func (*IntKeyEncoder) Encode

func (e *IntKeyEncoder) Encode(key any) (string, error)

type KeyEncoder

type KeyEncoder interface {
	Encode(key any) (string, error)
}

type StringKeyEncoder

type StringKeyEncoder struct{}

func NewStringKeyEncoder

func NewStringKeyEncoder() *StringKeyEncoder

func (*StringKeyEncoder) Encode

func (e *StringKeyEncoder) Encode(key any) (string, error)

type UUIDKeyEncoder

type UUIDKeyEncoder struct{}

func NewUUIDKeyEncoder

func NewUUIDKeyEncoder() *UUIDKeyEncoder

func (*UUIDKeyEncoder) Encode

func (e *UUIDKeyEncoder) Encode(key any) (string, error)

Jump to

Keyboard shortcuts

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