Discover Packages
github.com/wunderlist/ttlcache
package
module
Version:
v0.0.0-...-7dbceb0
Opens a new window with list of versions in this module.
Published: Aug 1, 2018
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 17 modules, 16 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
TTLCache - an in-memory LRU cache with expiration
TTLCache is a minimal wrapper over a string map in golang, entries of which are
Thread-safe
Auto-Expiring after a certain time
Auto-Extending expiration on Gets
Usage
import (
"time"
"github.com/wunderlist/ttlcache"
)
func main () {
cache := ttlcache.NewCache(time.Second)
cache.Set("key", "value")
value, exists := cache.Get("key")
count := cache.Count()
}
Expand ▾
Collapse ▴
Documentation
¶
Cache is a synchronised map of items that auto-expire once stale
NewCache is a helper to create instance of the Cache struct
Count returns the number of items in the cache
(helpful for tracking memory leaks)
Get is a thread-safe way to lookup items
Every lookup, also touches the item, hence extending it's life
Set is a thread-safe way to add new items to the map
Item represents a record in the cache map
Source Files
¶
Click to show internal directories.
Click to hide internal directories.