Clone this repo:
  1. eb52994 Code quality improvements (#67) by Dmitry Verkhoturov · 9 weeks ago master
  2. 14eae34 Add method PeekOrAdd to LRU Cache (#52) by MoonFruit · 6 months ago v0.5.4
  3. 7f827b3 Merge pull request #58 from MichaelMure/master by Jeff Mitchell · 12 months ago v0.5.3
  4. 881666a Add go mod version string by Jeff Mitchell · 12 months ago v0.5.2
  5. 6714091 Merge pull request #57 from kevburnsjr/resize by Jeff Mitchell · 12 months ago

golang-lru

This provides the lru package which implements a fixed-size thread safe LRU cache. It is based on the cache in Groupcache.

Documentation

Full docs are available on Godoc

Example

Using the LRU is very simple:

l, _ := New(128)
for i := 0; i < 256; i++ {
    l.Add(i, nil)
}
if l.Len() != 128 {
    panic(fmt.Sprintf("bad len: %v", l.Len()))
}