8000 GitHub - dkumor/golang-lru-timedcache: simple extension to golang-lru which allows time based expiration of keys.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dkumor/golang-lru-timedcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCoverage StatusGoDoc

golang-lru-timedcache

Simple wrapper for golang-lru which allows time based expiration of keys.

The cache is indexed by both an key and an id.

//Cache of size 20,000 with expiration set to 60,000ms (1 min)
tc, err := NewTimedCache(20000, 60000, nil)

keyid := 5
tc.Set("stringkey",keyid, "value")

//v is "value"
v, ok := tc.GetByName("stringkey")
v, ok = tc.GetByID(5)

//Removing can be done by ID or by name - removing by one automatically
//removes the other, so no need to call both
tc.RemoveID(5)
tc.RemoveName("stringkey")

//Since there is both an id and an index, we can set a value only knowing
//its id (or update only knowing id)
tc.SetID(3,"secondvalue")

//To change a value by ID without changing associated string key, use Update
tc.Update(3,"thirdvalue")

//Clears the cache
tc.Purge()

About

simple extension to golang-lru which allows time based expiration of keys.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0