1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/router/middleware/cache.go

25 lines
524 B
Go
Raw Normal View History

2016-05-02 21:21:25 +02:00
package middleware
import (
"github.com/drone/drone/cache"
"github.com/gin-gonic/gin"
2017-03-16 12:14:02 +02:00
"github.com/urfave/cli"
2016-05-02 21:21:25 +02:00
)
// Cache is a middleware function that initializes the Cache and attaches to
// the context of every http.Request.
func Cache(cli *cli.Context) gin.HandlerFunc {
v := setupCache(cli)
return func(c *gin.Context) {
cache.ToContext(c, v)
}
}
// helper function to create the cache from the CLI context.
func setupCache(c *cli.Context) cache.Cache {
return cache.NewTTL(
c.Duration("cache-ttl"),
)
}