- Notifications
You must be signed in to change notification settings - Fork19
🗃 Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more. Go 通用的缓存使用库,通过包装各种常用的驱动,来提供统一的使用API,便于使用。
License
gookit/cache
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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.Cache
interface. 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/bigcache
Internal:
- file internal driverdriver_file.go
- memory internal driverdriver_memory.go
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/cache
All cache driver implemented thecache.Cache
interface. So, You can add any custom driver.
typeCacheinterface {// basic operationHas(keystring)boolGet(keystring)anySet(keystring,valany,ttl time.Duration) (errerror)Del(keystring)error// multi operationGetMulti(keys []string)map[string]anySetMulti(valuesmap[string]any,ttl time.Duration) (errerror)DelMulti(keys []string)error// clear and closeClear()errorClose()error}
package mainimport ("fmt""github.com/gookit/cache""github.com/gookit/cache/gcache""github.com/gookit/cache/gocache""github.com/gookit/cache/goredis""github.com/gookit/cache/redis")funcmain() {// register one(or some) cache drivercache.Register(cache.DvrFile,cache.NewFileCache(""))// cache.Register(cache.DvrMemory, cache.NewMemoryCache())cache.Register(gcache.Name,gcache.New(1000))cache.Register(gocache.Name,gocache.NewGoCache(cache.OneDay,cache.FiveMinutes))cache.Register(redis.Name,redis.Connect("127.0.0.1:6379","",0))cache.Register(goredis.Name,goredis.Connect("127.0.0.1:6379","",0))// setting default driver namecache.DefaultUse(gocache.Name)// quick use.(it is default driver)//// setcache.Set("name","cache value",cache.TwoMinutes)// getval:=cache.Get("name")// delcache.Del("name")// get: "cache value"fmt.Print(val)// More ...// fc := cache.Driver(gcache.Name)// fc.Set("key", "value", 10)// fc.Get("key")}
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")
- gookit/ini Go config management, use INI files
- gookit/rux Simple and fast request router for golang HTTP
- gookit/gcli build CLI application, tool library, running CLI commands
- gookit/slog Lightweight, extensible, configurable logging library written in Go
- gookit/event Lightweight event manager and dispatcher implements by Go
- gookit/cache Provide a unified usage API by packaging various commonly used drivers.
- gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
- gookit/color A command-line color library with true color support, universal API methods and Windows support
- gookit/filter Provide filtering, sanitizing, and conversion of golang data
- gookit/validate Use for data validation and filtering. support Map, Struct, Form data
- gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
- More, please seehttps://github.com/gookit
MIT
About
🗃 Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more. Go 通用的缓存使用库,通过包装各种常用的驱动,来提供统一的使用API,便于使用。