lru

package
v0.0.0-...-68e76a8 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lru provides a LRU cache implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictionListener

type EvictionListener func(key string, value interface{})

EvictionListener functions will be notified when an element from the LRU is removed via evition (not deletion or replacement).

type LRU

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

LRU is the basic implementation of an LRU cache

func New

func New(size int, listener EvictionListener) *LRU

New will create a LRU instance with the given size of elements

func (*LRU) Delete

func (l *LRU) Delete(key string)

Delete will remove an entry for the given key if it exists

func (*LRU) Exists

func (l *LRU) Exists(key string) bool

Exists will determine if there is an entry for the given key

func (*LRU) Get

func (l *LRU) Get(key string) interface{}

Get will fetch the value for the given key or return nil if it does not exist

func (*LRU) Peek

func (l *LRU) Peek(key string) interface{}

Peek will fetch the value for the given key or return nil if it does not exist. This function will not update the LRU index.

func (*LRU) Set

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

Set will add/replace the given key with the specified value.

func (*LRU) Size

func (l *LRU) Size() int

Size reports the number of active elements in the LRU

Jump to

Keyboard shortcuts

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