cache

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMaxSize is returned when the given max size is not positive.
	ErrInvalidMaxSize = errors.New("max size must be > 0")
)

Functions

This section is empty.

Types

type LRUExpireCache

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

LRUExpireCache is a cache that ensures the mostly recently accessed keys are returned with a ttl beyond which keys are forcibly expired.

func NewLRUExpireCache

func NewLRUExpireCache(maxSize int) (*LRUExpireCache, error)

NewLRUExpireCache creates an expiring cache with the given size

func (*LRUExpireCache) Add

func (c *LRUExpireCache) Add(
	key string,
	value interface{},
	ttl time.Duration,
)

Add adds the value to the cache at key with the specified maximum duration.

func (*LRUExpireCache) Get

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

Get returns the value at the specified key from the cache if it exists and is not expired, or returns false.

Jump to

Keyboard shortcuts

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