cache

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache provides a simple interface for cache implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoop = errors.New("noop cacher")

Functions

func ContextWithNoCache added in v0.24.0

func ContextWithNoCache(parent context.Context) context.Context

ContextWithNoCache creates a new context with the no cache key/value added to the parent context.

func Key added in v0.24.0

func Key(args ...string) string

Key formats a slice of string arguments in a uniform, standard manner. Useful for when multiple parameters compose the cache key, and their order needs to remain the same.

func UseCache added in v0.24.0

func UseCache(ctx context.Context) bool

UseCache reports whether or not we can attempt to get data from the cache.

Types

type Cacher added in v0.20.0

type Cacher interface {
	// Del deletes the given key(s).
	Del(context.Context, ...string) error
	// Get returns the bytes stored under the given key.
	Get(context.Context, string) ([]byte, error)
	// Set stores a value under a given key, for as long
	// as the given duration.
	Set(context.Context, string, interface{}, time.Duration) error
}

Cacher defines the methods of any cache client.

func Default added in v0.23.0

func Default() Cacher

Default returns the default Cacher.

func NewNoop added in v0.24.2

func NewNoop(shouldErr bool) Cacher

NewNoop returns a new Noop Cacher. It can be configured to error, or not error, for all operations.

type Noop added in v0.24.2

type Noop struct {
	// contains filtered or unexported fields
}

Noop provides a no-op Cacher, useful for testing or other environments where a real Cacher cannot be used.

func (Noop) Del added in v0.24.2

func (n Noop) Del(ctx context.Context, keys ...string) error

func (Noop) Get added in v0.24.2

func (n Noop) Get(ctx context.Context, key string) ([]byte, error)

func (Noop) Set added in v0.24.2

func (n Noop) Set(ctx context.Context, key string, data interface{}, expiration time.Duration) error

type PrefixedCacher added in v0.24.2

type PrefixedCacher struct {
	// contains filtered or unexported fields
}

PrefixedCacher wraps a Cacher, and prefixes all cache keys.

func NewPrefixedCacher added in v0.24.2

func NewPrefixedCacher(c Cacher, keyPrefix string) *PrefixedCacher

NewPrefixedCacher returns a new PrefixedCacher instance.

func (*PrefixedCacher) Del added in v0.24.2

func (p *PrefixedCacher) Del(ctx context.Context, keys ...string) error

func (*PrefixedCacher) Get added in v0.24.2

func (p *PrefixedCacher) Get(ctx context.Context, key string) ([]byte, error)

func (*PrefixedCacher) Set added in v0.24.2

func (p *PrefixedCacher) Set(ctx context.Context, key string, v interface{}, d time.Duration) error

Directories

Path Synopsis
Package redis provides a wrapper around github.com/go-redis/redis, specifically to satisfy the cache.Cacher interface.
Package redis provides a wrapper around github.com/go-redis/redis, specifically to satisfy the cache.Cacher interface.

Jump to

Keyboard shortcuts

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