caching

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureCaching

func ConfigureCaching()

ConfigureCaching is used to setup caching, if the configuration caching impl is redis, then redis will be used. If any other value is provided including empty it will be an in memory cache. Default is in memory. If using redis, implement configs for URL, Port, Username, and Password.

Types

type Caching

type Caching interface {
	CheckCache(ctx context.Context, key string) (bool, []byte)
	AddToCache(ctx context.Context, key string, value []byte, ttl int64)
}

Caching interfaces for implementing caching, for retrieving records, and checking for existence, and adding to a cache with a TTL

var (
	//Cache implementation. Injected object will have CheckCache and AddToCache available.
	Cache Caching
)

type MemoryClient

type MemoryClient struct {
}

MemoryClient for implementing in memory cache.

func (*MemoryClient) AddToCache

func (c *MemoryClient) AddToCache(ctx context.Context, key string, value []byte, ttl int64)

AddToCache takes in Context for tracing, key for storing in the cache, a value in the form of a byte array for storing in the cache, a TTL for how long from now the record will exist. If the key exists, the value is not nil, and the TTL is not expired then the record will be added to the cache.

func (*MemoryClient) CheckCache

func (c *MemoryClient) CheckCache(ctx context.Context, key string) (bool, []byte)

CheckCache method for checking if the cache has a key matching the string provided. The Context is used for tracing.

type RedisClient

type RedisClient struct {
}

RedisClient holds values related to connecting and using redis for caching.

func (*RedisClient) AddToCache

func (c *RedisClient) AddToCache(ctx context.Context, key string, value []byte, ttl int64)

AddToCache takes in a context for tracing, a key of the record to be stored, a []byte to be stored, and a ttl in milliseconds for how long the record should live.

func (*RedisClient) CheckCache

func (c *RedisClient) CheckCache(ctx context.Context, key string) (bool, []byte)

CheckCache takes in a context for tracing and a key for searching redis. Returns whether it found the record and the []byte of the record.

Jump to

Keyboard shortcuts

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