cachingtest

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cachingtest contains helpers for testing code that uses caching package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithGlobalCache

func WithGlobalCache(c context.Context, caches map[string]caching.BlobCache) context.Context

WithGlobalCache installs given BlobCaches as "global" in the context.

'caches' is a map from a namespace to BlobCache instance. If some other namespace is requested, the corresponding caching.GlobalCache call will panic.

Types

type BlobCache

type BlobCache struct {
	LRU *lru.Cache[string, []byte] // the underlying LRU cache
	Err error                      // if non-nil, will be returned by Get and Set
}

BlobCache implements caching.BlobCache on top of lru.Cache for testing.

Useful for mocking caching.GlobalCache in tests. See also WithGlobalCache below.

func NewBlobCache

func NewBlobCache() *BlobCache

NewBlobCache initializes empty blob cache with unlimited capacity.

func (*BlobCache) Get

func (b *BlobCache) Get(c context.Context, key string) ([]byte, error)

Get returns a cached item or ErrCacheMiss if it's not in the cache.

func (*BlobCache) Set

func (b *BlobCache) Set(c context.Context, key string, value []byte, exp time.Duration) error

Set unconditionally overwrites an item in the cache.

Jump to

Keyboard shortcuts

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