ruleset.go 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. package client
  2. import (
  3. "github.com/kataras/iris/cache/cfg"
  4. "github.com/kataras/iris/cache/client/rule"
  5. "github.com/kataras/iris/cache/ruleset"
  6. "github.com/kataras/iris/context"
  7. )
  8. // DefaultRuleSet is a list of the default pre-cache validators
  9. // which exists in ALL handlers, local and remote.
  10. var DefaultRuleSet = rule.Chained(
  11. // #1 A shared cache MUST NOT use a cached response to a request with an
  12. // Authorization header field
  13. rule.HeaderClaim(ruleset.AuthorizationRule),
  14. // #2 "must-revalidate" and/or
  15. // "s-maxage" response directives are not allowed to be served stale
  16. // (Section 4.2.4) by shared caches. In particular, a response with
  17. // either "max-age=0, must-revalidate" or "s-maxage=0" cannot be used to
  18. // satisfy a subsequent request without revalidating it on the origin
  19. // server.
  20. rule.HeaderClaim(ruleset.MustRevalidateRule),
  21. rule.HeaderClaim(ruleset.ZeroMaxAgeRule),
  22. // #3 custom No-Cache header used inside this library
  23. // for BOTH request and response (after get-cache action)
  24. rule.Header(ruleset.NoCacheRule, ruleset.NoCacheRule),
  25. )
  26. // NoCache disables the cache for a particular request,
  27. // can be used as a middleware or called manually from the handler.
  28. func NoCache(ctx context.Context) {
  29. ctx.Header(cfg.NoCacheHeader, "true")
  30. }