cache

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache defines a deliberately small cache contract and an in-process implementation. Distributed stores can implement the same four methods.

Index

Constants

This section is empty.

Variables

View Source
var ErrMiss = errors.New("cache miss")

Functions

func GetJSON

func GetJSON[T any](ctx context.Context, store Store, key string) (T, error)

func PutJSON

func PutJSON[T any](ctx context.Context, store Store, key string, value T, lifetime time.Duration) error

func RememberJSON

func RememberJSON[T any](ctx context.Context, store Store, key string, lifetime time.Duration, load func(context.Context) (T, error)) (T, error)

Types

type Memory

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

func NewMemory

func NewMemory() *Memory

func (*Memory) Flush

func (memory *Memory) Flush(_ context.Context) error

func (*Memory) Forget

func (memory *Memory) Forget(_ context.Context, key string) error

func (*Memory) Get

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

func (*Memory) Prune

func (memory *Memory) Prune() int

Prune removes expired entries and returns the number removed.

func (*Memory) Put

func (memory *Memory) Put(_ context.Context, key string, value []byte, lifetime time.Duration) error

type Store

type Store interface {
	Get(context.Context, string) ([]byte, error)
	Put(context.Context, string, []byte, time.Duration) error
	Forget(context.Context, string) error
	Flush(context.Context) error
}

Jump to

Keyboard shortcuts

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