cache

package
v2.0.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cache defines a common interface for cache implementations that can be used by PiService implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Return the string that was set for key (or "" if unset) and an Error
	// if the implementation failed.
	// NOTE: a cache miss *should not* return an error.
	GetValue(ctx context.Context, key string) (string, error)
	// Store the value string with the provided key, returning an error if
	// the implementation failed.
	SetValue(ctx context.Context, key string, value string) error
}

Cache defines an interface for a cache implementation that can be used to store the results of a calculation for subsequent lookup requests.

type NoopCache

type NoopCache struct{}

NoopCache implements Cache interface without any real caching.

func NewNoopCache

func NewNoopCache() *NoopCache

Creates a no-operation Cache implementation that satisfies the interface requirements without performing any real caching. All values are silently dropped by SetValue and calls to GetValue always return an empty string.

func (*NoopCache) GetValue

func (n *NoopCache) GetValue(ctx context.Context, key string) (string, error)

Always returns an empty string and no error for every key.

func (*NoopCache) SetValue

func (n *NoopCache) SetValue(ctx context.Context, key, value string) error

Ignores the value and returns nil error.

type RedisCache

type RedisCache struct {
	*redis.Pool
}

RedisCache implements Cache interface backed by a Redis store.

func NewRedisCache

func NewRedisCache(ctx context.Context, endpoint string, options ...RedisCacheOption) *RedisCache

Return a new Cache implementation using Redis as a backend.

func (*RedisCache) GetValue

func (r *RedisCache) GetValue(ctx context.Context, key string) (string, error)

Returns the string value stored in Redis under key, if present, or an empty string.

func (*RedisCache) SetValue

func (r *RedisCache) SetValue(ctx context.Context, key, value string) error

Store the string key:value pair in Redis.

type RedisCacheOption

type RedisCacheOption func(*RedisCache)

Jump to

Keyboard shortcuts

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