cache

package
v1.5.0-dev14 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheFull error = errors.New("cache is full")
View Source
var ErrCacheTooCostly error = errors.New("item too costly for cache")
View Source
var ErrCacheWrongType error = errors.New("requested cache exists with that name, but a different type")

Functions

This section is empty.

Types

type Cache

type Cache[T any] interface {
	Get(key string) (T, bool)
	Set(key string, value T, cost uint64, expiresInSeconds int64) error
	SetWithDefaultTTL(key string, value T, cost uint64) error
	Delete(key string)
	Close()
}

type MockCache added in v1.0.1

type MockCache[T any] struct {
	// contains filtered or unexported fields
}

MockCache is a simple map-based cache usable in tests without using a real cache.

func NewMockCache added in v1.0.1

func NewMockCache[T any]() MockCache[T]

func (MockCache[T]) Close added in v1.0.1

func (m MockCache[T]) Close()

func (MockCache[T]) Delete added in v1.0.1

func (m MockCache[T]) Delete(key string)

func (MockCache[T]) Get added in v1.0.1

func (m MockCache[T]) Get(key string) (T, bool)

func (MockCache[T]) Set added in v1.0.1

func (m MockCache[T]) Set(key string, value T, cost uint64, expiresInSeconds int64) error

func (MockCache[T]) SetWithDefaultTTL added in v1.2.1

func (m MockCache[T]) SetWithDefaultTTL(key string, value T, cost uint64) error

type MockCacheItem added in v1.0.1

type MockCacheItem[T any] struct {
	Value  T
	Cost   uint64
	Expiry int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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