Clone this repo:
  1. 59383c4 lru.Get(): avoid nil pointer dereference (#56) by Sami Kerola · 2 days ago master
  2. ff8f6c9 Fix typo: 'exsists' (#50) by Eduardo Cáceres · 2 weeks ago
  3. 7087cb7 remove defer keyword to avoid overhead (#53) by guanw · 3 months ago v0.5.1
  4. 20f1fb7 Add go.mod by Mitchell Hashimoto · 9 months ago v0.5.0
  5. 369ebec fmt by Mitchell Hashimoto · 9 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()))
}