cache

package
v0.0.0-...-8575daa Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2020 License: AGPL-3.0, Apache-2.0 Imports: 7 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

	// Name returns the name of the cache
	Name() string
}

Cache 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 CacheOptions

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

CacheOptions contains options for initializaing a cache

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) Name

func (l *LRU) Name() string

Name returns the name of 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 {
	Name                   string
	Size                   int
	DefaultExpiry          time.Duration
	InvalidateClusterEvent string
}

LRUOptions contains options for initializing LRU cache

type Provider

type Provider interface {
	// NewCache creates a new cache with given options.
	NewCache(opts *CacheOptions) Cache
	// Connect opens a new connection to the cache using specific provider parameters.
	Connect() error
	// Close releases any resources used by the cache provider.
	Close() error
}

Provider is a provider for Cache

func NewProvider

func NewProvider() Provider

NewProvider creates a new CacheProvider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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