lru

package
v5.24.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: AGPL-3.0, 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 Cache

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

Cache is a thread-safe fixed size LRU cache.

func New

func New(size int) *Cache

New creates an LRU of the given size.

func NewWithParams

func NewWithParams(size int, name string, defaultExpiry int64, invalidateClusterEvent string) *Cache

NewWithParams creates an LRU with the given parameters.

func (*Cache) Add

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

Add adds the given key and value to the store without an expiry.

func (*Cache) AddWithDefaultExpires

func (c *Cache) AddWithDefaultExpires(key string, value interface{})

AddWithDefaultExpires adds the given key and value to the store with the default expiry.

func (*Cache) AddWithExpiresInSecs

func (c *Cache) AddWithExpiresInSecs(key string, value interface{}, expireAtSecs int64)

AddWithExpiresInSecs adds the given key and value to the cache with the given expiry.

func (*Cache) Get

func (c *Cache) Get(key string) (value interface{}, ok bool)

Get returns the value stored in the cache for a key, or nil if no value is present. The ok result indicates whether value was found in the cache.

func (*Cache) GetInvalidateClusterEvent

func (c *Cache) GetInvalidateClusterEvent() string

GetInvalidateClusterEvent returns the cluster event configured when this cache was created.

func (*Cache) GetOrAdd

func (c *Cache) GetOrAdd(key string, value interface{}, ttl time.Duration) (actual interface{}, loaded bool)

GetOrAdd returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored. This API intentionally deviates from the Add-only variants above for simplicity. We should simplify the entire API in the future.

func (*Cache) Keys

func (c *Cache) Keys() []string

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

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Name

func (c *Cache) Name() string

Name identifies this cache instance among others in the system.

func (*Cache) Purge

func (c *Cache) Purge()

Purge is used to completely clear the cache.

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove deletes the value for a key.

type CacheProvider

type CacheProvider struct{}

CacheProvider is an implementation of cache.Provider to create a new Lru Cache

func (*CacheProvider) Close

func (c *CacheProvider) Close()

Close releases any resources used by the cache provider.

func (*CacheProvider) Connect

func (c *CacheProvider) Connect()

Connect opens a new connection to the cache using specific provider parameters.

func (*CacheProvider) NewCache

func (c *CacheProvider) NewCache(size int) cache.Cache

NewCache creates a new lru.Cache with given size.

func (*CacheProvider) NewCacheWithParams

func (c *CacheProvider) NewCacheWithParams(size int, name string, defaultExpiry int64, invalidateClusterEvent string) cache.Cache

NewCacheWithParams creates a new lru.Cache with the given parameters.

Jump to

Keyboard shortcuts

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