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 // 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.

            Source Files