cache

package
v0.0.0-...-b22b80b Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 2 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 {
	Add(key []byte, value interface{}) error
	AddWithExpiration(key []byte, value interface{}, expiration time.Duration) error
	Get(key []byte) (value interface{}, found bool)
	Set(key []byte, value interface{}) error
	SetWithExpiration(key []byte, value interface{}, expiration time.Duration) error
}

Cache is an anstract cache layer

type GoCache

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

GoCache is the caching layer implemented by go-cache.

func NewGoCache

func NewGoCache(defaultExpiration, cleanupInterval time.Duration) *GoCache

NewGoCache creates a go-cache cache with a given default expiration duration and cleanup interval.

func (*GoCache) Add

func (gc *GoCache) Add(key []byte, value interface{}) error

Add adds an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired, using the default expiration. Returns an error otherwise.

func (*GoCache) AddWithExpiration

func (gc *GoCache) AddWithExpiration(key []byte, value interface{}, expiration time.Duration) error

AddWithExpiration adds an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired, using specified expiration. Returns an error otherwise.

func (*GoCache) Get

func (gc *GoCache) Get(key []byte) (interface{}, bool)

Get gets an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*GoCache) Set

func (gc *GoCache) Set(key []byte, value interface{}) error

Set adds an item to the cache, replacing any existing item, using the default expiration.

func (*GoCache) SetWithExpiration

func (gc *GoCache) SetWithExpiration(key []byte, value interface{}, expiration time.Duration) error

SetWithExpiration adds an item to the cache, replacing any existing item, using specified expiration.

Jump to

Keyboard shortcuts

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