cache

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 3 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 interface {
	Get(key interface{}) (data interface{}, ok bool)
	Add(key interface{}, data interface{})
	Remove(key interface{})
}

Cache is a generic interface that can be implemented by most types of caches.

func New

func New(conf config.CacheConfig) (Cache, error)

type Disabled

type Disabled struct{}

Disabled implements the Cache interface but implements no-op methods that return false. This allows callers to interact with a cache without having to check if it's enabled.

func (*Disabled) Add

func (d *Disabled) Add(key interface{}, data interface{})

func (*Disabled) Get

func (d *Disabled) Get(key interface{}) (data interface{}, ok bool)

func (*Disabled) Remove

func (d *Disabled) Remove(key interface{})

type TTL

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

TTL is a wrapper around a thread-safe LRU cache that adds a time-to-live value to each entry.

func NewTTL

func NewTTL(conf config.CacheConfig) (cache *TTL, err error)

func (*TTL) Add

func (c *TTL) Add(key interface{}, data interface{})

Add stores data in the cache by key.

func (*TTL) Get

func (c *TTL) Get(key interface{}) (data interface{}, ok bool)

Get returns data from the cache by key or false if the key does not exist or has expired.

func (*TTL) Remove

func (c *TTL) Remove(key interface{})

Remove removes data from the cache by key.

Jump to

Keyboard shortcuts

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