cache

package
v0.9.70 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const NoCache = time.Duration(0)

NoCache is passed as TTL to indicate that no expiration should be set.

Variables

This section is empty.

Functions

func GetDecode

func GetDecode[T any](ctx context.Context, cache Cache, key string) (T, error)

GetDecode retrieves a value of type T from the cache, decoding it from gob format. If the value is not found, it returns the zero value of T and no error. Best to use pointer to T, to distinguish between "not found" and "found but empty" cases.

func SetEncode

func SetEncode[T any](ctx context.Context, cache Cache, key string, value T, ttl time.Duration) error

SetEncode serializes a value of type T using gob encoding and stores it in the cache. Value should be passed by value, not by pointer.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string, ttl time.Duration) error
	Invalidate(ctx context.Context, key string) error
}

type Engine

type Engine interface {
	Cache
	Shutdown(ctx context.Context) error
}

type NoopCache

type NoopCache struct{}

NoopCache is a no-op implementation of Cache.

func NewNoop

func NewNoop() *NoopCache

func (NoopCache) Get

func (NoopCache) Get(_ context.Context, key string) (string, error)

func (NoopCache) Invalidate

func (NoopCache) Invalidate(_ context.Context, key string) error

func (NoopCache) Set

func (NoopCache) Set(_ context.Context, key string, value string, ttl time.Duration) error

func (NoopCache) Shutdown

func (NoopCache) Shutdown(_ context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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