Versions in this module Expand all Collapse all v0 v0.0.2 Dec 14, 2025 v0.0.1 Dec 5, 2025 Changes in this version + var ErrFailedToCreateZeroValue = errors.New("failed to create zero item") + var ErrInvalidConfig = errors.New("invalid config") + var ErrKeyExists = errors.New("key already exists") + var ErrKeyExpired = errors.New("key expired") + var ErrKeyNotFound = errors.New("key not found") + type Cache interface + Cleanup func(ctx context.Context) error + Close func() error + Delete func(ctx context.Context, key string) error + Drain func(ctx context.Context) (map[string][]byte, error) + Get func(ctx context.Context, key string, opts ...GetOption) ([]byte, error) + GetAndDelete func(ctx context.Context, key string) ([]byte, error) + Set func(ctx context.Context, key string, value []byte, opts ...Option) error + SetOrFail func(ctx context.Context, key string, value []byte, opts ...Option) error + type GetOption func(*getOptions) + func AndDefaultTTL() GetOption + func AndDelete() GetOption + func AndSetTTL(ttl time.Duration) GetOption + func AndSetValidUntil(validUntil time.Time) GetOption + func AndUpdateTTL(ttl time.Duration) GetOption + type Item interface + Marshal func() ([]byte, error) + Unmarshal func(data []byte) error + type MemoryCache struct + func NewMemory(ttl time.Duration) *MemoryCache + func (m *MemoryCache) Cleanup(_ context.Context) error + func (m *MemoryCache) Close() error + func (m *MemoryCache) Delete(_ context.Context, key string) error + func (m *MemoryCache) Drain(_ context.Context) (map[string][]byte, error) + func (m *MemoryCache) Get(_ context.Context, key string, opts ...GetOption) ([]byte, error) + func (m *MemoryCache) GetAndDelete(ctx context.Context, key string) ([]byte, error) + func (m *MemoryCache) Set(_ context.Context, key string, value []byte, opts ...Option) error + func (m *MemoryCache) SetOrFail(_ context.Context, key string, value []byte, opts ...Option) error + type Option func(*options) + func WithTTL(ttl time.Duration) Option + func WithValidUntil(validUntil time.Time) Option + type RedisCache struct + func NewRedis(config RedisConfig) (*RedisCache, error) + func (r *RedisCache) Cleanup(_ context.Context) error + func (r *RedisCache) Close() error + func (r *RedisCache) Delete(ctx context.Context, key string) error + func (r *RedisCache) Drain(ctx context.Context) (map[string][]byte, error) + func (r *RedisCache) Get(ctx context.Context, key string, opts ...GetOption) ([]byte, error) + func (r *RedisCache) GetAndDelete(ctx context.Context, key string) ([]byte, error) + func (r *RedisCache) Set(ctx context.Context, key string, value []byte, opts ...Option) error + func (r *RedisCache) SetOrFail(ctx context.Context, key string, value []byte, opts ...Option) error + type RedisConfig struct + Client *redis.Client + Prefix string + TTL time.Duration + URL string + type Typed struct + func NewTyped[T Item](storage Cache) *Typed[T] + func (c *Typed[T]) Cleanup(ctx context.Context) error + func (c *Typed[T]) Close() error + func (c *Typed[T]) Delete(ctx context.Context, key string) error + func (c *Typed[T]) Drain(ctx context.Context) (map[string]T, error) + func (c *Typed[T]) Get(ctx context.Context, key string, opts ...GetOption) (T, error) + func (c *Typed[T]) GetAndDelete(ctx context.Context, key string) (T, error) + func (c *Typed[T]) Set(ctx context.Context, key string, value T, opts ...Option) error + func (c *Typed[T]) SetOrFail(ctx context.Context, key string, value T, opts ...Option) error