cache

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deinit added in v0.4.0

func Deinit()

Deinit stops the cache and ensures that all open connections to external services are closed before the application exits.

func Get

func Get[T any](key string, t T) (T, bool)

Get returns a value from the cache. When there is no valid cache item available, the function will return the passed parameter t.

func Init

func Init(mode Mode, lifetime time.Duration, dsn Dsn) error

Init initializes the caching system. The cache implementation used is chosen by the supplied Mode. The function might return an error if a configuration issue occurred.

func Invalidate

func Invalidate[T any](key string, t T) bool

Invalidate the cache item with the given key and type. The function returns whether an item has been invalidated or not.

func Update

func Update[T any](key string, value T) error

Update adds or updates the given value to the cache with the given key.

Types

type Dsn

type Dsn string

Dsn is the information necessary to connect to a remote server like redis. It is necessary for some cache implementations.

type Mode

type Mode string

Mode specifies what cache implementation should be used

const (
	ModeMemory Mode = "memory"
	ModeRedis  Mode = "redis"
)

Available cache modes

type Provider

type Provider interface {
	Get(key string, t reflect.Type) (interface{}, bool)
	Update(key string, t reflect.Type, value interface{}) error
	Invalidate(key string, t reflect.Type) bool
	Shutdown()
}

Provider specifies the interface that different cache implementations must provide.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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