Neko handler for cache management.
package main
import (
"time"
"github.com/rocwong/neko"
nc "github.com/neko-contrib/cache"
)
func main() {
app := neko.Classic()
app.Use(nc.Generate(nc.Options{}))
m.GET("/", func(ctx *neko.Context) {
cache := ctx.MustGet(nc.MemoryStore).(nc.Cache)
cache.Set("foo", "bar", 10 * time.Second)
})
m.GET("/get", func(ctx *neko.Context) {
cache := ctx.MustGet(nc.MemoryStore).(nc.Cache)
v, found := cache.Get("foo")
ctx.Text(v.(string))
})
app.Run(":3000")
}
cache.Options {
// Store cache store. Default is 'MemoryStore'
Store string
// Config stores configuration.
Config string
// Interval GC interval time in seconds. Default is 60.
Interval int
}
app.Use(cache.Generate(cache.Options{}))