cache is a Go cache manager. It can use many cache adapters. The repo is inspired by database/sql
.
go get github.com/beego/beego/v2/client/cache
As of now this cache support memory, Memcache and Redis.
First you must import it
import (
"github.com/beego/beego/v2/client/cache"
)
Then init a Cache (example with memory)
bm := cache.NewMemoryCache(60)
Use it like this:
bm.Put("astaxie", 1, 10 * time.Second)
bm.Get("astaxie")
bm.IsExist("astaxie")
bm.Delete("astaxie")
interval means the gc time. The cache will check at each time interval, whether item has expired.
Memcache use the gomemcache client.
Redis use the redigo client.