cache

package
v1.20.76 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 4 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 {
	// Set a key with value to the cache. Returns true if an item was
	// evicted.
	Set(key, value interface{}) bool

	// Get an item from the cache by key. Returns the value if it exists,
	// and a bool stating whether or not it existed.
	Get(key interface{}) (interface{}, bool)

	// Keys returns a slice of all the keys in the cache
	Keys() []interface{}

	// Len returns the number of items present in the cache
	Len() int

	// Cap returns the total number of items the cache can retain
	Cap() int

	// Purge removes all items from the cache
	Purge()

	// Del deletes an item from the cache by key. Returns if an item was
	// actually deleted.
	Del(key interface{}) bool

	// Del deletes an item from the cache by value. Returns if an item was
	// actually deleted.
	DelByValue(value interface{}) bool
}

func NewLRUCache

func NewLRUCache(name string, cap int, opts ...Option) Cache

New creates a new Cache with cap entries that expire after ttl has elapsed since the item was added, modified or accessed.

type EvictCallback

type EvictCallback func(key interface{}, value interface{})

type Option

type Option func(*cache)

func WithEvictCallBack

func WithEvictCallBack(callback EvictCallback) Option

func WithReset

func WithReset() Option

func WithTTL

func WithTTL(val time.Duration) Option

func WithValue2Key

func WithValue2Key() Option

Jump to

Keyboard shortcuts

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