Awesome
lru
Package lru implements an LRU cache.
Get started
Install
go get github.com/hslam/lru
Import
import "github.com/hslam/lru"
Usage
Example
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()
}
Output
Hello world
License
This package is licensed under a MIT license (Copyright (c) 2021 Meng Huang)
Author
lru was written by Meng Huang.