cache

package
v2.3.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 3 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] struct {
	// contains filtered or unexported fields
}

Cache is a set of unique keys of type K.

Cache implements epoch-based expiry. Each PERIOD current keys are marked as stale and stale keys are discarded. This means that effective per-key expiry time is in between PERIOD and 2*PERIOD.

func NewCache

func NewCache[K comparable]() *Cache[K]

NewCache returns new instance of cache.

func Provide

func Provide[K comparable](lc fx.Lifecycle) *Cache[K]

Provide cache.

func (*Cache[K]) Contains

func (c *Cache[K]) Contains(k K) bool

Contains checks if map contains given key.

func (*Cache[K]) GetAll

func (c *Cache[K]) GetAll() []K

GetAll returns a copy of current state of cache.

State is returned as a list in an arbitrary order.

func (*Cache[K]) NewEpochForTest

func (c *Cache[K]) NewEpochForTest()

NewEpochForTest triggers manual epoch rotation.

Should be used only in tests.

func (*Cache[K]) Put

func (c *Cache[K]) Put(k K)

Put inserts k into the cache.

func (*Cache[K]) Start

func (c *Cache[K]) Start()

Start starts the periodic epoch rotation in background.

func (*Cache[K]) Stop

func (c *Cache[K]) Stop()

Stop stops all the background tasks of the cache.

Jump to

Keyboard shortcuts

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