Documentation
¶
Index ¶
- Variables
- func CalclateExpires(d *ResponseDirectives, resHeader http.Header, heuristicExpirationRatio float64, ...) time.Time
- type ExtendedRule
- type RequestDirectives
- type ResponseDirectives
- type Shared
- type SharedOption
- func ExtendedRules(rules []ExtendedRule) SharedOption
- func HeuristicExpirationRatio(ratio float64) SharedOption
- func HeuristicallyCacheableStatusCodes(statusCodes []int) SharedOption
- func StoreRequestWithSetCookieHeader() SharedOption
- func UnderstoodMethods(methods []string) SharedOption
- func UnderstoodStatusCodes(statusCodes []int) SharedOption
Constants ¶
This section is empty.
Variables ¶
var ErrNegativeRatio = errors.New("invalid heuristic expiration ratio (< 0)")
Functions ¶
func CalclateExpires ¶
Types ¶
type ExtendedRule ¶ added in v0.7.0
type ExtendedRule interface {
// Cacheable returns true and and the expiration time if the response is cacheable.
Cacheable(req *http.Request, res *http.Response) (ok bool, age time.Duration)
}
ExtendedRule is an extended rule. Like proxy_cache_valid of NGINX. Rules are applied only when there is no Cache-Control header and the expiration time cannot be calculated. THIS IS NOT RFC 9111.
type RequestDirectives ¶
type RequestDirectives struct {
// max-age https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.1
MaxAge *uint32
// max-stale https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.2
MaxStale *uint32
// min-fresh https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.3
MinFresh *uint32
// no-cache https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.4
NoCache bool
// no-store https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.5
NoStore bool
// no-transform https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.6
NoTransform bool
// only-if-cached https://www.rfc-editor.org/rfc/rfc9111#section-5.2.1.7
OnlyIfCached bool
}
func ParseRequestCacheControlHeader ¶
func ParseRequestCacheControlHeader(headers []string) *RequestDirectives
ParseRequestCacheControlHeader parses the Cache-Control header of a request.
type ResponseDirectives ¶
type ResponseDirectives struct {
// max-age https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.1
MaxAge *uint32
// must-revalidate https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.2
MustRevalidate bool
// must-understand https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.3
MustUnderstand bool
// no-cache https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.4
NoCache bool
// no-store https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.5
NoStore bool
// no-transform https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.6
NoTransform bool
// private https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.7
Private bool
// proxy-revalidate https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.8
ProxyRevalidate bool
// public https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.9
Public bool
// s-maxag https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.10
SMaxAge *uint32
// stale-while-revalidate https://www.rfc-editor.org/rfc/rfc9111#section-4.2.4 https://www.rfc-editor.org/rfc/rfc5861
StaleWhileRevalidate *uint32
// stale-if-error https://www.rfc-editor.org/rfc/rfc9111#section-4.2.4 https://www.rfc-editor.org/rfc/rfc5861
StaleIfError *uint32
}
func ParseResponseCacheControlHeader ¶
func ParseResponseCacheControlHeader(headers []string) *ResponseDirectives
ParseResponseCacheControlHeader parses the Cache-Control header of a response.
type Shared ¶
type Shared struct {
// contains filtered or unexported fields
}
Shared is a shared cache that implements RFC 9111. The following features are not implemented - Private cache. - Request directives.
func NewShared ¶
func NewShared(opts ...SharedOption) (*Shared, error)
NewShared returns a new Shared cache handler.
type SharedOption ¶
SharedOption is an option for Shared.
func ExtendedRules ¶ added in v0.7.0
func ExtendedRules(rules []ExtendedRule) SharedOption
ExtendedRules sets the extended rules.
func HeuristicExpirationRatio ¶
func HeuristicExpirationRatio(ratio float64) SharedOption
HeuristicExpirationRatio sets the heuristic expiration ratio.
func HeuristicallyCacheableStatusCodes ¶
func HeuristicallyCacheableStatusCodes(statusCodes []int) SharedOption
HeuristicallyCacheableStatusCodes sets the heuristically cacheable status codes.
func StoreRequestWithSetCookieHeader ¶ added in v0.7.0
func StoreRequestWithSetCookieHeader() SharedOption
StoreRequestWithSetCookieHeader enables storing request with Set-Cookie header.
func UnderstoodMethods ¶
func UnderstoodMethods(methods []string) SharedOption
UnderstoodMethods sets the understood methods.
func UnderstoodStatusCodes ¶
func UnderstoodStatusCodes(statusCodes []int) SharedOption
UnderstoodStatusCodes sets the understood status codes.