Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more.
Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more.
Generic cache use and cache manager for golang.
Provide a unified usage API by packaging various commonly used drivers.
All cache driver implemented the
cache.Cacheinterface. So, You can add any custom driver.
Packaged Drivers:
goredis https://github.com/go-redis/redisredis https://github.com/gomodule/redigomemcached https://github.com/bradfitz/gomemcachebuntdb https://github.com/tidwall/buntdbboltdb https://github.com/etcd-io/bboltbadger https://github.com/dgraph-io/badgernutsdb https://github.com/xujiajun/nutsdbgoleveldb https://github.com/syndtr/goleveldbgcache https://github.com/bluele/gcachegocache https://github.com/patrickmn/go-cachebigcache https://github.com/allegro/bigcacheInternal:
Notice: The built-in implementation is relatively simple and is not recommended for production environments; the production environment recommends using the third-party drivers listed above.
The package supports 3 last Go versions and requires a Go version with modules support.
go get github.com/gookit/cacheAll cache driver implemented the cache.Cache interface. So, You can add any custom driver.
type Cache interface {
// basic operation
Has(key string) bool
Get(key string) any
Set(key string, val any, ttl time.Duration) (err error)
Del(key string) error
// multi operation
GetMulti(keys []string) map[string]any
SetMulti(values map[string]any, ttl time.Duration) (err error)
DelMulti(keys []string) error
// clear and close
Clear() error
Close() error
}…gords := goredis.Connect("127.0.0.1:6379", "", 0)
gords.WithOptions(cache.WithPrefix("cache_"), cache.WithEncode(true))
cache.Register(goredis.Name, gords)
// set
// real key is: "cache_name"
cache.Set("name", "cache value", cache.TwoMinutes)
// get: "cache value"
val := cache.Get("name")MIT
No open issues yet, or sync has not completed.