lru

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2019 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package lru implement a thread safe lru cache inspired by https://github.com/golang/groupcache/tree/master/lru

Index

Constants

View Source
const (
	// default LRU size
	Default_LRU_Size = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

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

LRU implements a thread safe fixed size LRU cache

func NewLRUCache

func NewLRUCache(size int) *LRU

NewLRUCache return a given size LRU

func (*LRU) Cap

func (l *LRU) Cap() int

return the LRU max capacity

func (*LRU) Contains

func (l *LRU) Contains(key interface{}) bool

Cotains check if the LRU contains the given key

func (*LRU) Get

func (l *LRU) Get(key interface{}) (value interface{}, ok bool)

Get value from LRU by key

func (*LRU) GetOrSet

func (l *LRU) GetOrSet(key, value interface{}) (newValue interface{}, isGet bool)

return the value if the key exist, otherwise update the key by given value similar with redis SETNX

func (*LRU) Info

func (l *LRU) Info() (hits int, misses int, maxSize int, currentSize int)

return the LRU running information

func (*LRU) Keys

func (l *LRU) Keys() []interface{}

return all keys the LRU hold from oldest to newest

func (*LRU) Len

func (l *LRU) Len() int

return the LRU length

func (*LRU) PopOldest

func (l *LRU) PopOldest() (key, value interface{})

Remove and return the oldest item from LRU

func (*LRU) Purge

func (l *LRU) Purge()

Purge use to clear all items in LRU

func (*LRU) Remove

func (l *LRU) Remove(key interface{}) bool

Remove the given key item return if the key has existed before

func (*LRU) Set

func (l *LRU) Set(key, value interface{}) (evicted bool)

Add a new item into LRU

Jump to

Keyboard shortcuts

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