Back to

Package cachingtest

Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module:


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


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.

type BlobCache

type BlobCache struct {
	LRU *lru.Cache // underlying LRU cache, create it with lru.New(capacity).
	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 (*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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier