concache
is in-memory key:value cache. concache
provides thread-safe map[string]interface{}
with expiration times.
concache
a high-performance solution to this by sharding the map with minimal time spent waiting for locks.
https://godoc.org/github.com/octu0/concache
$ go get github.com/octu0/concache
import(
"time"
"github.com/octu0/concache"
)
func main(){
cache := concache.New(
concache.WithDefaultExpiration(5 * time.Second),
concache.WithCleanupInterval(10 * time.Minute),
)
cache.Set("hello", "123", 1 * time.Second)
cache.SetDefault("world", "456")
if value, ok := cache.Get("hello"); ok {
println("hello " + value.(string))
}
if value, ok := cache.Get("world"); ok {
println("world " + value.(string))
}
time.Sleep(1 * time.Second)
if _, ok := cache.Get("hello"); ok != true {
println("hello expired")
}
if _, ok := cache.Get("world"); ok {
println("world not expired")
}
}
MIT, see LICENSE file for details.