cache

package
v0.0.0-...-3c22c5d Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LruBaseSize defines LRU size
	LruBaseSize = 128
)

Variables

View Source
var (
	// ErrUnexpectedType happens on non expected type
	ErrUnexpectedType = errors.New("unexpected type")
)

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Expire time.Time
	Value  interface{}
}

Entry lRU entry

type LruCache

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

LruCache defines an LRU cache with expiration

func NewLRUCache

func NewLRUCache(ttl, freq time.Duration) (*LruCache, error)

NewLRUCache instantiates LRU cache

func (*LruCache) Add

func (c *LruCache) Add(_ context.Context, k string, v interface{}) error

Add LRU entry

func (*LruCache) Get

func (c *LruCache) Get(_ context.Context, k string) (interface{}, error)

Get LRU entry

func (*LruCache) Len

func (c *LruCache) Len() int

Len returns cache size

func (*LruCache) Terminate

func (c *LruCache) Terminate()

Terminate stop worker

type Redis

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

Redis implements a cache with expiration

func NewRedis

func NewRedis(cl *redis.Client, ttl time.Duration) *Redis

NewRedis instantiates redis cache

func (*Redis) Add

func (r *Redis) Add(ctx context.Context, k string, v interface{}) error

Add Cache entry

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, k string) (interface{}, error)

Get cache entry

func (*Redis) Terminate

func (r *Redis) Terminate()

Terminate stop cache

Jump to

Keyboard shortcuts

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