README.md
# heapcache[](https://travis-ci.org/turboezh/heapcache)[](https://github.com/turboezh/heapcache/releases)[](https://goreportcard.com/report/github.com/turboezh/heapcache)[](https://codeclimate.com/github/turboezh/heapcache/maintainability)[](https://codeclimate.com/github/turboezh/heapcache/test_coverage)[](https://godoc.org/github.com/turboezh/heapcache) This cache implementation is based on priority queue (see [Heap](https://golang.org/pkg/container/heap/)).It uses user-defined comparator to evaluate priorities of cached items. Items with lowest priorities will be evicted first. Features: - simple standard data structure; - no write locks on get operations; - capacity may be changed at any time. # RequirementsGo >= 1.11 # Documentationhttps://godoc.org/github.com/turboezh/heapcache # Examples ## Cache```gotype Foo struct { Value int Timestamp time.Time} item1 := Foo{10, time.Now()}item2 := Foo{20, time.Now().Add(time.Second)} cache := New(10, func(a, b interface{}) bool { return a.(*Foo).Timestamp.Before(b.(*Foo).Timestamp)})``` ## Add item```gocache.Add("one", &item1)cache.Add("two", &item2) ``` ## Get item```goitem, exists := cache.Get("one")if !exists { // `foo` doesn't exists in cache // `item` is nil}// cache returns `interface{}` so we need to assert type (if need so)item = item.(*Foo) // = &item1``` ## Check item```go// check if cache contain all keys ok := cache.All("one", "two") // check if cache contain any of keys ok := cache.Any("one", "two")``` ## Remove item```go// Remove returns false if there is no item in cachewasRemoved := cache.Remove("one")``` ## Support on BeerpayHey dude! Help me out for a couple of :beers:! [](https://beerpay.io/turboezh/heapcache) [](https://beerpay.io/turboezh/heapcache?focus=wish)