Gocache is a Golang library for caching.
You need golang 1.13 to use gocache.
go get github.com/ahmetask/gocache/v2
package main
import (
"fmt"
"github.com/ahmetask/gocache/v2"
"time"
)
func main() {
cache := gocache.NewCache(5*time.Minute, 5*time.Second)
cache.Set("foo", "bar", gocache.Eternal)
cache.Set("foo2", 1, 5*time.Second)
res, success := cache.Get("foo")
fmt.Println(res)
fmt.Println(success)
}
package main
import (
"github.com/ahmetask/gocache/v2"
"time"
)
func main() {
cache := gocache.NewCache(5*time.Minute, 5*time.Second)
serverConfig := gocache.ServerConfig{
CachePtr: cache,
Port: "8080",
}
gocache.NewCacheServer(serverConfig)
}
package main
import (
"github.com/ahmetask/gocache/v2"
)
func main() {
request := gocache.AddCacheRequest{Key: "key", Value: "any interface", Life: 4}
gocache.SaveCache("serviceIp", request)
var r interface{}
gocache.GetCache("serviceIp", "key", &r)
}
package main
import (
"github.com/ahmetask/gocache/v2"
"time"
)
func main() {
cache := gocache.NewCache(5*time.Minute, 5*time.Second)
cache.StartWorkerPoolWith(2)
cache.AddBackground("key", "value", gocache.Eternal)
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.