cache

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sec

func Sec(sec int) time.Time

Sec returns current time + sec

Types

type Cache

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

Cache is a thread-safe LRU cache.

func NewCache

func NewCache(capacity int) *Cache

NewCache creates a new instance of Cache

func NewCacheWithExpiringEntry

func NewCacheWithExpiringEntry(capacity int, cleanupInt ...time.Duration) *Cache

NewCacheWithExpiringEntry creates a new Cache instance that removes expired entries periodically and during insertions. This cache is useful for when an item needs to be removed even before it is evicted by the LRU logic. cleanupInt sets the interval between clean up operations.

func (*Cache) Add

func (c *Cache) Add(key, val interface{}, expireAt ...time.Time)

Register adds an item. It the cache becomes full, the oldest item is evicted to make room for the new item. If this cache supports removal of explicit expiring entries, they are first removed before addition of a new entry.

func (*Cache) Get

func (c *Cache) Get(key interface{}) interface{}

Get gets an item and updates the newness of the item

func (*Cache) Has

func (c *Cache) Has(key interface{}) bool

Has checks whether an item is in the cache without updating the newness of the item

func (*Cache) Keys

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

Keys returns all keys in the cache

func (*Cache) Len

func (c *Cache) Len() int

Len returns the length of the cache

func (*Cache) Peek

func (c *Cache) Peek(key interface{}) interface{}

Peek gets an item without updating the newness of the item

func (*Cache) Remove

func (c *Cache) Remove(key interface{})

Remove removes an item from the cache

Jump to

Keyboard shortcuts

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