1 Star 0 Fork 0

sonysoul/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache.go 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
/* Package cache provides server-side caching capabilities with rich support of options and rules.
Use it for server-side caching, see the `iris#Cache304` for an alternative approach that
may fit your needs most.
Example code:
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/cache"
)
func main(){
app := iris.Default()
middleware := cache.Handler(2 *time.Minute)
app.Get("/hello", middleware, h)
app.Run(iris.Addr(":8080"))
}
func h(ctx iris.Context) {
ctx.HTML("<h1> Hello, this should be cached. Every 2 minutes it will be refreshed, check your browser's inspector</h1>")
}
*/
package cache
import (
"time"
"github.com/kataras/iris/cache/client"
"github.com/kataras/iris/context"
)
// Cache accepts the cache expiration duration
// if the expiration <=2 seconds then expiration is taken by the "cache-control's maxage" header
// returns context.Handler, which you can use as your default router or per-route handler
//
// All types of response can be cached, templates, json, text, anything.
//
// Use it for server-side caching, see the `iris#Cache304` for an alternative approach that
// may fit your needs most.
//
// You can add validators with this function.
func Cache(expiration time.Duration) *client.Handler {
return client.NewHandler(expiration)
}
// Handler accepts one single parameter:
// the cache expiration duration
// if the expiration <=2 seconds then expiration is taken by the "cache-control's maxage" header
// returns context.Handler.
//
// All types of response can be cached, templates, json, text, anything.
//
// Use it for server-side caching, see the `iris#Cache304` for an alternative approach that
// may fit your needs most.
//
// it returns a context.Handler which can be used as a middleware, for more options use the `Cache`.
//
// Examples can be found at: https://github.com/kataras/iris/tree/master/_examples/#caching
func Handler(expiration time.Duration) context.Handler {
h := Cache(expiration).ServeHTTP
return h
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sonysoul/iris.git
git@gitee.com:sonysoul/iris.git
sonysoul
iris
iris
v10.5.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385