mirror of
https://github.com/kataras/iris.git
synced 2026-01-18 09:25:59 +00:00
add Cache304 as an alternative to the server-side kataras/iris/cache middleware - it can perform better with less server overheat but it comes with a cost of 304 instead of 200 so custom clients must make that check
Former-commit-id: b0ba68c528c870fe060e2825c35689771a1d3680
This commit is contained in:
11
cache/cache.go
vendored
11
cache/cache.go
vendored
@@ -1,4 +1,7 @@
|
||||
/* Package cache provides cache capabilities with rich support of options and rules.
|
||||
/* 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:
|
||||
|
||||
@@ -37,6 +40,9 @@ import (
|
||||
//
|
||||
// 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)
|
||||
@@ -49,6 +55,9 @@ func Cache(expiration time.Duration) *client.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
|
||||
|
||||
2
cache/client/handler.go
vendored
2
cache/client/handler.go
vendored
@@ -163,7 +163,7 @@ func (h *Handler) ServeHTTP(ctx context.Context) {
|
||||
|
||||
// if it's valid then just write the cached results
|
||||
entry.CopyHeaders(ctx.ResponseWriter().Header(), response.Headers())
|
||||
context.SetLastModified(ctx, e.LastModified)
|
||||
ctx.SetLastModified(e.LastModified)
|
||||
ctx.StatusCode(response.StatusCode())
|
||||
ctx.Write(response.Body())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user