cache

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpiringLRU

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

ExpiringLRU caches values for string keys with a time based expiration and an LRU based eviciton policy.

func New

func New(opts Options) *ExpiringLRU

New constructs an ExpiringLRU with the given options.

func (*ExpiringLRU) Delete

func (e *ExpiringLRU) Delete(key string)

Delete explicitly removes a key from the cache if it exists.

func (*ExpiringLRU) Get

func (e *ExpiringLRU) Get(key string, fn func() (interface{}, error)) (
	value interface{}, err error)

Get returns the value for some key if it exists and is valid. If not it will call the provided function. Concurrent calls will dedupe as best as they are able. If the function returns an error, it is not cached and further calls will try again.

type Options

type Options struct {
	// Expiration is how long an entry will be valid. It is not
	// affected by LRU or anything: after this duration, the object
	// is invalidated. A non-positive value means no expiration.
	Expiration time.Duration

	// Capacity is how many objects to keep in memory.
	Capacity int
}

Options controls the details of the expiration policy.

Jump to

Keyboard shortcuts

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