cache

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AgentCachePrefix is the common root to use to prefix all the cache
	// keys for any value regarding the Agent
	AgentCachePrefix = "agent"

	// NoExpiration maps to go-cache corresponding value
	NoExpiration = cache.NoExpiration
)

Variables

View Source
var Cache = cache.New(defaultExpire, defaultPurge)

Cache provides an in-memory key:value store similar to memcached

Functions

func BuildAgentKey

func BuildAgentKey(keys ...string) string

BuildAgentKey creates a cache key by joining the constant AgentCachePrefix and path elements passed as arguments. It is to be used by core agent packages to reuse the prefix constant

Types

type BasicCache

type BasicCache[R comparable] struct {
	// contains filtered or unexported fields
}

BasicCache is a simple threadsafe cache

func NewBasicCache

func NewBasicCache[R comparable]() *BasicCache[R]

NewBasicCache Creates new BasicCache

func (*BasicCache[R]) Add

func (b *BasicCache[R]) Add(k R, v interface{})

Add adds value to cache for specified key It will overwrite any existing value

func (*BasicCache[R]) Get

func (b *BasicCache[R]) Get(k R) (interface{}, bool)

Get gets interface for specified key and a boolean that's false when the key is not found

func (*BasicCache[R]) GetModified

func (b *BasicCache[R]) GetModified() int64

GetModified gets interface for specified key or error

func (*BasicCache[R]) Items

func (b *BasicCache[R]) Items() map[R]interface{}

Items returns a map with the elements in the cache

func (*BasicCache[R]) Remove

func (b *BasicCache[R]) Remove(k R)

Remove removes an entry from the cache if it exists

func (*BasicCache[R]) Size

func (b *BasicCache[R]) Size() int

Size returns the current size of the cache

Jump to

Keyboard shortcuts

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