Skip to content

Instantly share code, notes, and snippets.

@suntong
Created August 9, 2020 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/8345739c8bb4d01cae17d0540ad6d8d4 to your computer and use it in GitHub Desktop.
Save suntong/8345739c8bb4d01cae17d0540ad6d8d4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"github.com/hashicorp/golang-lru/simplelru"
)
func main() {
log.Println("Hello, playground")
evictCounter := 0
onEvicted := func(k interface{}, v interface{}) {
evictCounter++
}
l, err := simplelru.NewLRU(128, onEvicted)
if err != nil {
log.Fatalf("err: %v", err)
}
for i := 0; i < 256; i++ {
l.Add(fmt.Sprint(i), nil)
}
if l.Len() != 128 {
log.Fatalf("bad len: %v", l.Len())
}
if evictCounter != 128 {
log.Fatalf("bad evict count: %v", evictCounter)
}
for i, k := range l.Keys() {
log.Printf("%03d: %#v", i, k)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment