TTLCache is a minimal wrapper over a map of custom in golang, entries of which are
- Thread-safe
- Auto-Expiring after a certain time
- Managed auto-extending expiration on
Gets
import (
"time""github.com/ikoroteev/ttlcache"
)
funcmain () {
cache:=ttlcache.NewCache()
cache.Set("key", "value", time.Second)
cache.Set("key1", 24, time.Duration(500) *time.Millisecond)
cache.Set("key3", time.Second, time.Second)
value, exists:=cache.Get("key", true) // true - extend cache ttl, otherwise falsecount:=cache.Count()
}