You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3KB

  1. package client
  2. import (
  3. "github.com/kataras/iris/v12/cache/cfg"
  4. "github.com/kataras/iris/v12/cache/client/rule"
  5. "github.com/kataras/iris/v12/cache/ruleset"
  6. "github.com/kataras/iris/v12/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. }