cache

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache store element with a expired time

func New

func New(interval time.Duration) *Cache

New return *Cache

func (Cache) Get

func (c Cache) Get(key interface{}) interface{}

Get element in Cache, and drop when it expired

func (Cache) GetWithExpire

func (c Cache) GetWithExpire(key interface{}) (payload interface{}, expired time.Time)

GetWithExpire element in Cache with Expire Time

func (Cache) Put

func (c Cache) Put(key interface{}, payload interface{}, ttl time.Duration)

Put element in Cache with its ttl

type LruCache added in v1.17.3

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

LruCache is a thread-safe, in-memory lru-cache that evicts the least recently used entries from memory when (if set) the entries are older than maxAge (in seconds). Use the New constructor to create one.

func NewLRUCache added in v1.17.3

func NewLRUCache(options ...Option) *LruCache

NewLRUCache creates an LruCache

func (*LruCache) Delete added in v1.17.3

func (c *LruCache) Delete(key string)

Delete removes the value associated with a key.

func (*LruCache) Get added in v1.17.3

func (c *LruCache) Get(key interface{}) (interface{}, bool)

Get returns the interface{} representation of a cached response and a bool set to true if the key was found.

func (*LruCache) Set added in v1.17.3

func (c *LruCache) Set(key interface{}, value interface{})

Set stores the interface{} representation of a response for a given key.

type Option added in v1.17.3

type Option func(*LruCache)

Option is part of Functional Options Pattern

func WithAge added in v1.17.3

func WithAge(maxAge int64) Option

WithAge defined element max age (second)

func WithSize added in v1.17.3

func WithSize(maxSize int) Option

WithSize defined max length of LruCache

func WithUpdateAgeOnGet added in v1.17.3

func WithUpdateAgeOnGet() Option

WithUpdateAgeOnGet update expires when Get element

Jump to

Keyboard shortcuts

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