cache

package
v0.0.0-...-4b98c26 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 8 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 is a rudimentary key/value caching store backed by redis. It offers a Get/Set interface as well a its gzip compressed alternative GetCompressed/SetCompressed

func New

func New(client redis.UniversalClient) Cache

New returns a new Cache from a potentially nil redis client.

func (Cache) CheckStatus

func (c Cache) CheckStatus() (time.Duration, error)

CheckStatus checks that the cache is ready, or returns an error.

func (Cache) Clear

func (c Cache) Clear(key string)

Clear removes a key from the cache

func (Cache) Get

func (c Cache) Get(key string) ([]byte, bool)

Get fetch the cached asset at the given key, and returns true only if the asset was found.

func (Cache) GetCompressed

func (c Cache) GetCompressed(key string) (io.Reader, bool)

GetCompressed works like Get but expect a compressed asset that is uncompressed.

func (Cache) Keys

func (c Cache) Keys(prefix string) []string

Keys returns the list of keys with the given prefix. Note: it can be slow and should be used carefully.

func (Cache) MultiGet

func (c Cache) MultiGet(keys []string) [][]byte

MultiGet can be used to fetch several keys at once.

func (Cache) RefreshTTL

func (c Cache) RefreshTTL(key string, expiration time.Duration)

RefreshTTL can be used to update the TTL of an existing entry in the cache.

func (Cache) Set

func (c Cache) Set(key string, data []byte, expiration time.Duration)

Set stores an asset to the given key.

func (Cache) SetCompressed

func (c Cache) SetCompressed(key string, data []byte, expiration time.Duration)

SetCompressed works like Set but compress the asset data before storing it.

func (Cache) SetNX

func (c Cache) SetNX(key string, data []byte, expiration time.Duration)

SetNX stores the data in the cache only if the key doesn't exist yet.

Jump to

Keyboard shortcuts

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