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
Get
s
import (
"time"
"github.com/ikoroteev/ttlcache"
)
func main () {
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 false
count := cache.Count()
}