Package lru implements an LRU cache.
go get github.com/hslam/lru
import "github.com/hslam/lru"
package main
import (
"fmt"
"github.com/hslam/lru"
)
func main() {
var capacity = 1024
var free lru.Free = func(key, value interface{}) {}
l := lru.New(capacity, free)
key := 1
value := "Hello world"
cost := len(value)
r := l.Set(key, value, cost)
r.Done()
if v, r, ok := l.Get(key); ok {
fmt.Println(v)
r.Done()
}
l.Remove(key)
l.Reset()
}
Hello world
This package is licensed under a MIT license (Copyright (c) 2021 Meng Huang)
lru was written by Meng Huang.