lfu

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 lfu cache

Index

Constants

View Source
const (
	// default LFU size
	Default_LFU_Size = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LFU

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

LFU implements a thread safe fixed size LFU cache

func NewLFUCache

func NewLFUCache(size int) *LFU

NewLFUCache return a given size LFU

func (*LFU) Cap

func (l *LFU) Cap() int

return the LFU max capacity

func (*LFU) Contains

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

Cotains check if the LRU contains the given key

func (*LFU) Get

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

Get value from LFU by key

func (*LFU) GetOrSet

func (l *LFU) 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 (*LFU) Info

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

return the LFU running information

func (*LFU) Keys

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

return all keys the LRU hold from oldest to newest

func (*LFU) Len

func (l *LFU) Len() int

return the LFU length

func (*LFU) PopOldest

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

Remove and return the oldest item from LFU

func (*LFU) Purge

func (l *LFU) Purge()

Purge use to clear all items in LFU

func (*LFU) Remove

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

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

func (*LFU) Set

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

Add a new item into LFU

Jump to

Keyboard shortcuts

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