luci: Index | Files

package cachingtest

import ""

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


Package Files


func WithGlobalCache Uses

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 Uses

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 Uses

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 Uses

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

Set unconditionally overwrites an item in the cache.

Package cachingtest imports 5 packages (graph). Updated 2020-11-26. Refresh now. Tools for package owners.