cache

package
v0.0.0-...-a8786dc Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRedisCacheNotInstantiated = errors.New("redis client not instantiated, call NewRedisCacheInstance first")

Functions

func InitRedis

func InitRedis()

Types

type Cache

type Cache interface {
	handler.PersistedQueryCache
	Set(key string, value interface{}) error
	Del(key string) (int64, error)
}

type RedisCache

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

RedisCache is a struct which holds some defaults for cache entries, such as the ttl and a prefix for each key. The idea here is that you have can have multiple instances of this struct and they all use the one client in this pacakge.

func NewRedisCacheInstance

func NewRedisCacheInstance(keyPrefix string, ttl time.Duration) (*RedisCache, error)

func (*RedisCache) Add

func (c *RedisCache) Add(ctx context.Context, key string, value interface{})

Add adds a key-value pair to the cache. This is specifically made to implement the PersistedQueryCache of gqlgen, so you can pass an instance of RedisCache to gqlgen. If you are wanting to manipulate the redis cache more directly, you may wish to use Set instead.

func (*RedisCache) Del

func (c *RedisCache) Del(key string) (int64, error)

func (*RedisCache) Get

func (c *RedisCache) Get(ctx context.Context, key string) (interface{}, bool)

Gets a key-value pair from the cache. Part of the implementation of gqlgen's PersistedQueryCache so you can pass an isntance of RedisCache to a gqlgen handler.

func (*RedisCache) Set

func (c *RedisCache) Set(key string, value interface{}) error

Set adds a key-value pair to the cache. Main difference between this and Add is that it returns an error, which makes it more useful than Add outside of using it with gqlgen.

Jump to

Keyboard shortcuts

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