Cache library for golang. It supports expirable Cache, LFU, LRU and ARC.
- Supports expirable Cache, LFU, LRU and ARC.
- Auto-renewal cache items. (Optional)
- Goroutine safe.
- Supports event handlers which evict, purge, and add entry. (Optional)
- Automatically load cache if it doesn't exists. (Optional)
- Supports context.
- Supports shared cache.
- Supports generic interface.
- Supports managed by the Arena allocator. (Optional)
$ go get github.com/limpo1989/gcache
package main
import (
"context"
"fmt"
"github.com/limpo1989/gcache"
)
func main() {
gc := gcache.New[string, string](20).
LRU().
LoaderFunc(func(ctx context.Context, key string) (*string, error) {
value := "ok"
return &value, nil
}).
Build()
value, err := gc.Get(context.Background(), "key")
if err != nil {
panic(err)
}
fmt.Println("Get:", *value)
}This project initial code based from gcache written by bluele