cache

package
v0.95.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 1 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[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache consists of an LRU cache and the evicted items from the LRU cache. This data structure makes sure all the cached items can be retrieved either from the LRU cache or the evictedItems map. In spanmetricsprocessor's use case, we need to hold all the items during the current processing step for building the metrics. The evicted items can/should be safely removed once the metrics are built from the current batch of spans.

Important: This implementation is non-thread safe.

func NewCache

func NewCache[K comparable, V any](size int) (*Cache[K, V], error)

NewCache creates a Cache.

func (*Cache[K, V]) Add added in v0.64.0

func (c *Cache[K, V]) Add(key K, value V) bool

Add a value to the cache, returns true if an eviction occurred and updates the "recently used"-ness of the key.

func (*Cache[K, V]) Contains added in v0.87.0

func (c *Cache[K, V]) Contains(key K) bool

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (V, bool)

Get an item from the LRU cache or evicted items.

func (*Cache[K, V]) Len added in v0.64.0

func (c *Cache[K, V]) Len() int

Len returns the number of items in the cache.

func (*Cache[K, V]) Purge

func (c *Cache[K, V]) Purge()

Purge removes all the items from the LRU cache and evicted items.

func (*Cache[K, V]) RemoveEvictedItems

func (c *Cache[K, V]) RemoveEvictedItems()

RemoveEvictedItems cleans all the evicted items.

Jump to

Keyboard shortcuts

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