cache2

package
v5.25.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: AGPL-3.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is the error when the given key is not found

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Purge is used to completely clear the cache.
	Purge() error

	// Set adds the given key and value to the store without an expiry. If the key already exists,
	// it will overwrite the previous value.
	Set(key string, value interface{}) error

	// SetWithDefaultExpiry adds the given key and value to the store with the default expiry. If
	// the key already exists, it will overwrite the previoous value
	SetWithDefaultExpiry(key string, value interface{}) error

	// SetWithExpiry adds the given key and value to the cache with the given expiry. If the key
	// already exists, it will overwrite the previoous value
	SetWithExpiry(key string, value interface{}, ttl time.Duration) error

	// Get the content stored in the cache for the given key, and decode it into the value interface.
	// Return ErrKeyNotFound if the key is missing from the cache
	Get(key string, value interface{}) error

	// Remove deletes the value for a given key.
	Remove(key string) error

	// Keys returns a slice of the keys in the cache.
	Keys() ([]string, error)

	// Len returns the number of items in the cache.
	Len() (int, error)

	// GetInvalidateClusterEvent returns the cluster event configured when this cache was created.
	GetInvalidateClusterEvent() string
}

Cache (under package cache2) is a representation of a cache store that aims to replace cache.Cache

func NewLRU

func NewLRU(opts *LRUOptions) Cache

NewLRU creates an LRU of the given size.

type LRU

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

LRU is a thread-safe fixed size LRU cache.

func (*LRU) Get

func (l *LRU) Get(key string, value interface{}) error

Get the content stored in the cache for the given key, and decode it into the value interface. return ErrKeyNotFound if the key is missing from the cache

func (*LRU) GetInvalidateClusterEvent

func (l *LRU) GetInvalidateClusterEvent() string

GetInvalidateClusterEvent returns the cluster event configured when this cache was created.

func (*LRU) Keys

func (l *LRU) Keys() ([]string, error)

Keys returns a slice of the keys in the cache.

func (*LRU) Len

func (l *LRU) Len() (int, error)

Len returns the number of items in the cache.

func (*LRU) Purge

func (l *LRU) Purge() error

Purge is used to completely clear the cache.

func (*LRU) Remove

func (l *LRU) Remove(key string) error

Remove deletes the value for a key.

func (*LRU) Set

func (l *LRU) Set(key string, value interface{}) error

Set adds the given key and value to the store without an expiry. If the key already exists, it will overwrite the previous value.

func (*LRU) SetWithDefaultExpiry

func (l *LRU) SetWithDefaultExpiry(key string, value interface{}) error

SetWithDefaultExpiry adds the given key and value to the store with the default expiry. If the key already exists, it will overwrite the previoous value

func (*LRU) SetWithExpiry

func (l *LRU) SetWithExpiry(key string, value interface{}, ttl time.Duration) error

SetWithExpiry adds the given key and value to the cache with the given expiry. If the key already exists, it will overwrite the previoous value

type LRUOptions

type LRUOptions struct {
	Size                   int
	DefaultExpiry          time.Duration
	InvalidateClusterEvent string
}

LRUOptions contains options for initializing LRU cache

Jump to

Keyboard shortcuts

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