lrucache

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 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 Element

type Element struct {
	Key   interface{}
	Value interface{}
	// contains filtered or unexported fields
}

Element - node to store cache item

func (*Element) Next

func (e *Element) Next() *Element

Next - fetch older element

func (*Element) Prev

func (e *Element) Prev() *Element

Prev - fetch newer element

type LRUCache

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

LRUCache - a data structure that is efficient to insert/fetch/delete cache items [both O(1) time complexity]

func New

func New(capacity int) *LRUCache

New - create a new lru cache object

func (*LRUCache) Back

func (lc *LRUCache) Back() *Element

Back - get back element of lru cache

func (*LRUCache) Capacity

func (lc *LRUCache) Capacity() int

Capacity - capacity of lru cache

func (*LRUCache) Delete

func (lc *LRUCache) Delete(key interface{})

Delete - delete item by key from lru cache

func (*LRUCache) Front

func (lc *LRUCache) Front() *Element

Front - get front element of lru cache

func (*LRUCache) Get

func (lc *LRUCache) Get(key interface{}) (interface{}, bool)

Get - get value of key from lru cache with result

func (*LRUCache) Len

func (lc *LRUCache) Len() int

Len - length of lru cache

func (*LRUCache) Put

func (lc *LRUCache) Put(key interface{}, value interface{})

Put - put a cache item into lru cache

func (*LRUCache) Range

func (lc *LRUCache) Range(f func(key, value interface{}) bool)

Range - calls f sequentially for each key and value present in the lru cache

func (*LRUCache) Update

func (lc *LRUCache) Update(key interface{}, f func(value *interface{}))

Update - inplace update

type SyncCache

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

SyncCache - concurrent cache structure

func NewSyncCache

func NewSyncCache(capacity int, bucket int, timeout int64) *SyncCache

NewSyncCache - create sync cache `capacity` is lru cache length of each bucket store `capacity * bucket` count of element in SyncCache at most `timeout` is in seconds

func (*SyncCache) Delete

func (sc *SyncCache) Delete(key string)

Delete - delete item by key from sync cache

func (*SyncCache) Get

func (sc *SyncCache) Get(key string) (interface{}, bool)

Get - get value of key from sync cache with result

func (*SyncCache) Put

func (sc *SyncCache) Put(key string, value interface{})

Put - put a cache item into sync cache

Jump to

Keyboard shortcuts

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