cache

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 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 ConcurrentCounterCache

type ConcurrentCounterCache interface {
	// Add add a value to the cache,
	// Updates the "recently used"-ness of the key.
	Add(key interface{}, value *int64)

	// If the key is not existed in the cache, adds a value to the cache then return nil. And updates the "recently used"-ness of the key
	// If the key is already existed in the cache, do nothing and return the prior value
	AddIfAbsent(key interface{}, value *int64) (priorValue *int64)

	// Get returns key's value from the cache and updates the "recently used"-ness of the key.
	Get(key interface{}) (value *int64, isFound bool)

	// Remove removes a key from the cache.
	// Return true if the key was contained.
	Remove(key interface{}) (isFound bool)

	// Contains checks if a key exists in cache
	// Without updating the recent-ness.
	Contains(key interface{}) (ok bool)

	// Keys returns a slice of the keys in the cache, from oldest to newest.
	Keys() []interface{}

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

	// Purge clears all cache entries.
	Purge()
}

ConcurrentCounterCache cache the hotspot parameter

func NewLRUCacheMap

func NewLRUCacheMap(size int) ConcurrentCounterCache

type EvictCallback

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

EvictCallback is used to get a callback when a cache entry is evicted

type LRU

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

LRU implements a non-thread safe fixed size LRU cache

func NewLRU

func NewLRU(size int, onEvict EvictCallback) (*LRU, error)

NewLRU constructs an LRU of the given size

func (*LRU) Add

func (c *LRU) Add(key, value interface{})

func (*LRU) AddIfAbsent

func (c *LRU) AddIfAbsent(key interface{}, value interface{}) (priorValue interface{})

AddIfAbsent adds item only if key is not existed.

func (*LRU) Contains

func (c *LRU) Contains(key interface{}) (ok bool)

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*LRU) Get

func (c *LRU) Get(key interface{}) (value interface{}, isFound bool)

Get looks up a key's value from the cache.

func (*LRU) GetOldest

func (c *LRU) GetOldest() (key interface{}, value interface{}, ok bool)

GetOldest returns the oldest entry

func (*LRU) Keys

func (c *LRU) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LRU) Len

func (c *LRU) Len() int

Len returns the number of items in the cache.

func (*LRU) Peek

func (c *LRU) Peek(key interface{}) (value interface{}, isFound bool)

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LRU) Purge

func (c *LRU) Purge()

Purge is used to completely clear the cache.

func (*LRU) Remove

func (c *LRU) Remove(key interface{}) (isFound bool)

Remove removes the provided key from the cache, returning if the key was contained.

func (*LRU) RemoveOldest

func (c *LRU) RemoveOldest() (key interface{}, value interface{}, ok bool)

RemoveOldest removes the oldest item from the cache.

func (*LRU) Resize

func (c *LRU) Resize(size int) (evicted int)

Resize changes the cache size.

type LruCacheMap

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

LruCacheMap use LRU strategy to cache the most frequently accessed hotspot parameter

func (*LruCacheMap) Add

func (c *LruCacheMap) Add(key interface{}, value *int64)

func (*LruCacheMap) AddIfAbsent

func (c *LruCacheMap) AddIfAbsent(key interface{}, value *int64) (priorValue *int64)

func (*LruCacheMap) Contains

func (c *LruCacheMap) Contains(key interface{}) (ok bool)

func (*LruCacheMap) Get

func (c *LruCacheMap) Get(key interface{}) (value *int64, isFound bool)

func (*LruCacheMap) Keys

func (c *LruCacheMap) Keys() []interface{}

func (*LruCacheMap) Len

func (c *LruCacheMap) Len() int

func (*LruCacheMap) Purge

func (c *LruCacheMap) Purge()

func (*LruCacheMap) Remove

func (c *LruCacheMap) Remove(key interface{}) (isFound bool)

Jump to

Keyboard shortcuts

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