mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
some major improvements to the (server-side) cache middleware and an example of a client-side responsibility cache
Former-commit-id: 93d3a7a6f163c6d49f315f86d10e63f7b1b1d93a
This commit is contained in:
27
_examples/cache/client-side/main.go
vendored
Normal file
27
_examples/cache/client-side/main.go
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Package main shows how you can use the `WriteWithExpiration`
|
||||
// based on the "modtime", if it's newer than the request header then
|
||||
// it will refresh the contents, otherwise will let the client (99.9% the browser)
|
||||
// to handle the cache mechanism, it's faster than iris.Cache because server-side
|
||||
// has nothing to do and no need to store the responses in the memory.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
var modtime = time.Now()
|
||||
|
||||
func greet(ctx iris.Context) {
|
||||
ctx.Header("X-Custom", "my custom header")
|
||||
response := fmt.Sprintf("Hello World! %s", time.Now())
|
||||
ctx.WriteWithExpiration([]byte(response), modtime)
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Get("/", greet)
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user