-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #890 from kataras/dev
New Cache Middleware: iris.Cache304
- Loading branch information
Showing
13 changed files
with
222 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 ( | ||
"time" | ||
|
||
"github.com/kataras/iris" | ||
) | ||
|
||
const refreshEvery = 10 * time.Second | ||
|
||
func main() { | ||
app := iris.New() | ||
app.Use(iris.Cache304(refreshEvery)) | ||
// same as: | ||
// app.Use(func(ctx iris.Context) { | ||
// now := time.Now() | ||
// if modified, err := ctx.CheckIfModifiedSince(now.Add(-refresh)); !modified && err == nil { | ||
// ctx.WriteNotModified() | ||
// return | ||
// } | ||
|
||
// ctx.SetLastModified(now) | ||
|
||
// ctx.Next() | ||
// }) | ||
|
||
app.Get("/", greet) | ||
app.Run(iris.Addr(":8080")) | ||
} | ||
|
||
func greet(ctx iris.Context) { | ||
ctx.Header("X-Custom", "my custom header") | ||
ctx.Writef("Hello World! %s", time.Now()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.