A simple LRU cache in GoLang with custom evicton policies and Go generics support.
- A lightweight least recently used ("LRU") cache with no external dependencies.
- Go 1.18 generics.
- To define your own eviction policy, for example only evict from the cache when consumed memory or disk space exceeds some threshold.
Below is an example of the most basic LRU cache with a simple eviction policy based on a maximum number of keys. More examples are available in the API reference documentation.
package main
import (
"fmt"
"github.com/gogama/policy-lru"
)
func main() {
lru := policylru.New[string, string](policylru.MaxCount[string, string](10))
lru.Add("foo", "bar")
value, ok := lru.Get("foo")
fmt.Printf("In cache? %t. Value: %q.\n", ok, value)
}
This project is licensed under the terms of the Apache License 2.0.
The code for this project is heavily based on the code from package
lru
from
github.com/golang/groupcache.
The borrowed code is licensed under the
Apache License 2.0
Developer happiness on this project was boosted by JetBrains' generous donation of an open source license for their lovely GoLand IDE. ❤