Announcing a multifunction cache library for golang.
http://github.com/bluele/gcache
# Features
- Supports expirable Cache, LFU, LRU and ARC.
- Goroutine safe.
- Supports event handlers which evict and add entry. (Optional)
- Automatically load cache if it doesn't exists. (Optional)
# Automatically load value
package main
import (
"github.com/bluele/gcache"
"fmt"
)
func main() {
gc := gcache.New(20).
LRU().
LoaderFunc(func(key interface{}) (interface{}, error) {
return "ok", nil
}).
Build()
value, err := gc.Get("key")
if err != nil {
panic(err)
}
fmt.Println("Get:", value)
}
// output
Get: ok
# Manually set a key-value pair.
package main
import (
"github.com/bluele/gcache"
"fmt"
)
func main() {
gc := gcache.New(20).
LRU().
Build()
gc.Set("key", "ok")
value, err := gc.Get("key")
if err != nil {
panic(err)
}
fmt.Println("Get:", value)
}
// output
Get: ok
Please check https://github.com/bluele/gcache if you like it.
I'll be glad if you try to use it.
- Jun
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.