fifo

package
v0.0.0-...-4d13c9b Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: GPL-3.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

type EvictCallback func(EvictionReason, uuid.UUID, models.Record)

EvictCallback lets you know when an eviction has happened in the cache

type EvictionReason

type EvictionReason int

EvictionReason describes why the eviction happened

const (
	// Purged by calling reset
	Purged EvictionReason = iota

	// Popped manually from the cache
	Popped

	// Removed manually from the cache
	Removed

	// Dequeued by walking over due to being dequeued
	Dequeued
)

type FIFO

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

func NewFIFO

func NewFIFO(onEvict EvictCallback) *FIFO

NewFIFO implements a non-thread safe FIFO cache

func (*FIFO) Add

func (f *FIFO) Add(key uuid.UUID, value models.Record) bool

Add adds a key, value pair.

func (*FIFO) Contains

func (f *FIFO) Contains(key uuid.UUID) bool

Contains finds out if a key is present in the LRU cache

func (*FIFO) Dequeue

func (f *FIFO) Dequeue(fn func(uuid.UUID, models.Record) error) ([]KeyValue, error)

Dequeue iterates over the LRU cache removing an item upon each iteration.

func (*FIFO) Get

func (f *FIFO) Get(key uuid.UUID) (models.Record, bool)

Get returns back a value if it exists. Returns true if found.

func (*FIFO) Keys

func (f *FIFO) Keys() []uuid.UUID

Keys returns the keys as a slice

func (*FIFO) Len

func (f *FIFO) Len() int

Len returns the current length of the LRU cache

func (*FIFO) Pop

func (f *FIFO) Pop() (uuid.UUID, models.Record, bool)

Pop removes the last FIFO item with in the cache

func (*FIFO) Purge

func (f *FIFO) Purge()

Purge removes all items with in the cache, calling evict callback on each.

func (*FIFO) Remove

func (f *FIFO) Remove(key uuid.UUID) bool

Remove a value using it's key Returns true if a removal happened

func (*FIFO) Slice

func (f *FIFO) Slice() []KeyValue

Slice returns a snapshot of the KeyValue pairs.

type KeyValue

type KeyValue struct {
	Key   uuid.UUID
	Value models.Record
}

Jump to

Keyboard shortcuts

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