cache

package
v0.0.0-...-eb082ec Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

README

pkg/cache

In memory cache with ttl

currently being used to store [auth_token] -> user_config

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] interface {
	// Get returns the value for the given key.
	// If the key is not found, found will be false.
	Get(ctx context.Context, key string) (value T, found bool)

	// Sets the value for the given key.
	Set(ctx context.Context, key string, value T)
	// Removes the key from the cache.
	Remove(ctx context.Context, key string)
}

func New

func New[T any](config Config[T]) Cache[T]

func NewNoopCache

func NewNoopCache[T any]() Cache[T]

type Config

type Config[T any] struct {
	// How long the data is considered fresh
	// Subsequent requests in this time will try to use the cache
	Fresh time.Duration

	// Subsequent requests that are not fresh but within the stale time will return cached data but also trigger
	// fetching from the origin server
	Stale time.Duration

	// A handler that will be called to refetch data from the origin when necessary
	RefreshFromOrigin func(ctx context.Context, identifier string) (T, error)

	Logger *zap.Logger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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