Simple in-memory cache with TTL
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
README.md
get.go
reap.go
set.go
ttlcache.go
ttlcache_test.go

README.md

TTLCache

TTLCache is a very simple TTL based in-memory cache written in Go.

Build Status GoDoc Coverage

Usage

// error handling omitted for example

c, _ := NewTTLCache(time.Millisecond * 1000)

k := "testkey"
v := "testval"

c.Set(k, v)

r := c.Get(k)
fmt.Println(r.(string))

Expiration Callback

A callback can be specified to be called upon key expiration:

// error handling omitted for example

func callback(k string, v interface{}) {
    fmt.Printf("key %s expired\n", k)
}

c, _ := NewTTLCache(time.Millisecond * 1000)
c.SetCallback(callback)

k := "testkey"
v := "testval"

c.Set(k, v)