cache

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 3 Imported by: 2

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 ulc cache.

func New

func New(size int) (*Cache, error)

New creates an cache of the given size.

func NewWithEvict

func NewWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error)

NewWithEvict constructs a fixed size cache with the given eviction callback.

func (*Cache) Add

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

Add adds a value to the cache. Returns true if an eviction occurred.

func (*Cache) Contains

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

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*Cache) ContainsOrAdd

func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool)

ContainsOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.

func (*Cache) Get

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

Get looks up a key's value from the cache.

func (*Cache) Keys

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

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) Peek

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

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*Cache) Purge

func (c *Cache) Purge()

Purge is used to completely clear the cache.

func (*Cache) Remove

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

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type EvictCallback

type EvictCallback func(key interface{}, value interface{})

EvictCallback is used to get a callback when a cache entry is evicted

type UnLockCache

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

UnLockCache implements a non-thread safe fixed size UnLockCache cache

func NewUnLockCache

func NewUnLockCache(size int, onEvict EvictCallback) (*UnLockCache, error)

NewUnLockCache constructs an UnLockCache of the given size

func (*UnLockCache) Add

func (c *UnLockCache) Add(key, value interface{}) (evicted bool)

Add adds a value to the cache. Returns true if an eviction occurred.

func (*UnLockCache) Contains

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

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*UnLockCache) Get

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

Get looks up a key's value from the cache.

func (*UnLockCache) GetOldest

func (c *UnLockCache) GetOldest() (key interface{}, value interface{}, ok bool)

GetOldest returns the oldest entry

func (*UnLockCache) Keys

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

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

func (*UnLockCache) Len

func (c *UnLockCache) Len() int

Len returns the number of items in the cache.

func (*UnLockCache) Peek

func (c *UnLockCache) Peek(key interface{}) (value interface{}, ok bool)

Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*UnLockCache) Purge

func (c *UnLockCache) Purge()

Purge is used to completely clear the cache.

func (*UnLockCache) Remove

func (c *UnLockCache) Remove(key interface{}) (present bool)

Remove removes the provided key from the cache, returning if the key was contained.

func (*UnLockCache) RemoveOldest

func (c *UnLockCache) RemoveOldest() (key interface{}, value interface{}, ok bool)

RemoveOldest removes the oldest item from the cache.

Jump to

Keyboard shortcuts

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