internal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 2 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 an abstracted cache that provides a skeletal implementation, of the Cache interface to minimize the effort required to implement interface.

func New

func New(c Collection, cap int) *Cache

New return new abstracted cache.

func (*Cache) Cap

func (c *Cache) Cap() int

Cap Returns the cache capacity.

func (*Cache) Contains

func (c *Cache) Contains(key interface{}) (ok bool)

Contains Checks if a key exists in cache.

func (*Cache) DelSilently

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

DelSilently the key value silently without call onEvicted.

func (*Cache) Delete

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

Delete deletes the key value.

func (*Cache) Discard

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

Discard oldest entry from cache to make room for the new ones.

func (*Cache) Expiry

func (c *Cache) Expiry(key interface{}) (t time.Time, ok bool)

Expiry returns key value expiry time.

func (*Cache) Keys

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

Keys return cache records keys.

func (*Cache) Len

func (c *Cache) Len() int

Len Returns the number of items in the cache.

func (*Cache) Load

func (c *Cache) Load(key interface{}) (interface{}, bool)

Load returns key value.

func (*Cache) Peek

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

Peek returns key value without updating the underlying "rank".

func (*Cache) Purge

func (c *Cache) Purge()

Purge Clears all cache entries.

func (*Cache) RegisterOnEvicted

func (c *Cache) RegisterOnEvicted(f func(key, value interface{}))

RegisterOnEvicted registers a function, to call in its own goroutine when an entry is purged from the cache.

func (*Cache) RegisterOnExpired

func (c *Cache) RegisterOnExpired(f func(key, value interface{}))

RegisterOnExpired registers a function, to call in its own goroutine when an entry TTL elapsed.

func (*Cache) Resize

func (c *Cache) Resize(size int) int

Resize cache, returning number evicted

func (*Cache) SetTTL

func (c *Cache) SetTTL(ttl time.Duration)

SetTTL sets entries default TTL.

func (*Cache) Store

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

Store sets the value for a key.

func (*Cache) StoreWithTTL

func (c *Cache) StoreWithTTL(key, value interface{}, ttl time.Duration)

StoreWithTTL sets the key value with TTL overrides the default.

func (*Cache) TTL

func (c *Cache) TTL() time.Duration

TTL returns entries default TTL.

func (*Cache) Update

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

Update the key value without updating the underlying "rank".

type Collection

type Collection interface {
	Move(*Entry)
	Add(*Entry)
	Remove(*Entry)
	Discard() *Entry
	Len() int
	Init()
}

Collection represents the cache underlying data structure, and defines the functions or operations that can be applied to the data elements.

type Entry

type Entry struct {
	Key     interface{}
	Value   interface{}
	Element interface{}
	Exp     time.Time
	// contains filtered or unexported fields
}

Entry is used to hold a value in the cache.

Jump to

Keyboard shortcuts

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