lru

package module
v0.0.0-...-543b96b Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 3 Imported by: 0

README

go-lru

Simple thread-safe generic Go LRU cache implementation

Installation

go get github.com/notEpsilon/go-lru

Usage

using the cache is very simple

cache := lru.New[int, string](2) // give capacity

cache.Put(1, "fish")

value, err := cache.Get(1) // returns an error if the key wasn't found
if err != nil {
  panic(err)
}

fmt.Println(value) // fish

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUCache

type LRUCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func New

func New[K comparable, V any](capacity int) (*LRUCache[K, V], error)

func (*LRUCache[K, V]) Capacity

func (c *LRUCache[K, V]) Capacity() int

func (*LRUCache[K, V]) Contains

func (c *LRUCache[K, V]) Contains(key K) bool

func (*LRUCache[K, V]) Get

func (c *LRUCache[K, V]) Get(key K) (V, error)

func (*LRUCache[K, V]) Peek

func (c *LRUCache[K, V]) Peek(key K) (V, error)

func (*LRUCache[K, V]) Remove

func (c *LRUCache[K, V]) Remove(key K)

func (*LRUCache[K, V]) Set

func (c *LRUCache[K, V]) Set(key K, value V)

func (*LRUCache[K, V]) Size

func (c *LRUCache[K, V]) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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