fifo

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: GPL-3.0 Imports: 3 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 fifo cache.

func NewCache

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

NewCache creates an fifo of the given size.

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

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

GetOldest returns the oldest entry

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

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

PeekOrAdd 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) Purge

func (c *Cache) Purge()

Purge is used to completely clear the cache.

func (*Cache) Remove

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

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

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

RemoveOldest removes the oldest item from the cache.

func (*Cache) Resize

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

Resize changes the cache size.

type Fifo

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

Fifo implements a non-thread safe fixed size Fifo cache

func NewFifo

func NewFifo(size int) (*Fifo, error)

NewFifo constructs an Fifo of the given size

func (*Fifo) Add

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

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

func (*Fifo) Contains

func (c *Fifo) 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 (*Fifo) Get

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

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

func (*Fifo) GetOldest

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

GetOldest returns the oldest entry

func (*Fifo) Keys

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

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

func (*Fifo) Len

func (c *Fifo) Len() int

Len returns the number of items in the cache.

func (*Fifo) Peek

func (c *Fifo) 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 (*Fifo) Purge

func (c *Fifo) Purge()

Purge is used to completely clear the cache.

func (*Fifo) Remove

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

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

func (*Fifo) RemoveOldest

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

RemoveOldest removes the oldest item from the cache.

func (*Fifo) Resize

func (c *Fifo) Resize(size int) (evicted int)

Resize changes the cache size.

Jump to

Keyboard shortcuts

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