cache

package module
v0.0.0-...-907bac9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

cache-control

Documentation

Index

Constants

View Source
const (
	HeaderMaxAge       = "max-age"
	HeaderNoCache      = "no-cache"
	HeaderNoStore      = "no-store"
	HeaderMaxStale     = "max-stale"
	HeaderMinFresh     = "min-fresh"
	HeaderNoTransform  = "no-transform"
	HeaderOnlyIfCached = "only-if-cached"

	HeaderPublic               = "public"
	HeaderPrivate              = "private"
	HeaderSMaxAge              = "s-maxage"
	HeaderImmutable            = "immutable"
	HeaderStaleIfError         = "stale-if-error"
	HeaderMustRevalidate       = "must-revalidate"
	HeaderProxyRevalidate      = "proxy-revalidate"
	HeaderStaleWhileRevalidate = "stale-while-revalidate"
)

Cacheable HTTP header directives

Variables

View Source
var (
	ErrMaxAgeDeltaSeconds               = errors.New("invalid delta-seconds value in `max-age` directive")
	ErrSMaxAgeDeltaSeconds              = errors.New("invalid delta-seconds value in `s-maxage` directive")
	ErrMaxStaleDeltaSeconds             = errors.New("invalid delta-seconds value in `max-stale` directive")
	ErrMinFreshDeltaSeconds             = errors.New("invalid delta-seconds value in `min-fresh` directive")
	ErrStaleIfErrorDeltaSeconds         = errors.New("invalid delta-seconds value in `stale-if-error` directive")
	ErrStaleWhileRevalidateDeltaSeconds = errors.New("invalid delta-seconds value in `stale-while-revalidate` directive")

	ErrPublicDirectiveValue          = errors.New("public directive does not accept a value")
	ErrNoCacheDirectiveValue         = errors.New("no-cache directive does not accept a value")
	ErrNoStoreDirectiveValue         = errors.New("no-store directive does not accept a value")
	ErrImmutableDirectiveValue       = errors.New("immutable directive does not accept a value")
	ErrNoTransformDirectiveValue     = errors.New("no-transform directive does not accept a value")
	ErrOnlyIfCachedDirectiveValue    = errors.New("only-if-cached directive does not accept a value")
	ErrMustRevalidateDirectiveValue  = errors.New("must-revalidate directive does not accept a value")
	ErrProxyRevalidateDirectiveValue = errors.New("proxy-revalidate directive does not accept a value")
)
View Source
var (
	ErrMissingClosingQuote = errors.New("missing closing quote")
)

Functions

This section is empty.

Types

type RequestCacheDirective

type RequestCacheDirective struct {
	// max-age
	// MaxAge is the maximum time in seconds that a response can be considered fresh.
	// The client is not willing to accept a stale response if the max-stale directive
	// is not present.
	MaxAge int32

	// max-stale
	// MaxStale is the maximum time in seconds that a client is willing to accept a
	// stale response that has exceeded its freshness lifetime.
	MaxStale int32

	// min-fresh
	// MinFresh is the minimum time in seconds that a response must remain fresh,
	// calculated as the difference between its freshness lifetime and its current age.
	MinFresh int32

	// no-cache
	// NoCache is a boolean value that indicates whether a cache should validate
	// the response with the origin server before using a stored response to satisfy
	// the request.
	NoCache bool

	// no-store
	// NoStore is a boolean value that indicates whether a cache should store
	// any part of the request or response.
	NoStore bool

	// only-if-cached
	// OnlyIfCached is a boolean value that indicates whether the client only
	// wants to obtain a stored response and not send a request to the origin server.
	OnlyIfCached bool

	// Extensions is a list of cache-extension tokens with optional values
	// that can be used to extend the Cache-Control header field.
	Extensions []string
}

func NewRequestCacheDirective

func NewRequestCacheDirective(value string) (*RequestCacheDirective, error)

type ResponseCacheDirective

type ResponseCacheDirective struct {
	// MustRevalidate is a boolean value that indicates whether a cache
	// must revalidate a stored response on every request.
	MustRevalidate bool

	// NoCache is a map of field-name to boolean values that indicates whether
	// a cache should not use a stored response to satisfy a request if any of the
	// request-header field names are present in the list.
	NoCache map[string]bool

	// NoCachePresent is a boolean value that indicates whether the no-cache
	// directive was present in the response.
	NoCachePresent bool

	// NoStore is a boolean value that indicates whether a cache should not
	// store any part of the response or request.
	NoStore bool

	// NoTransform is a boolean value that indicates whether a cache should
	// not transform the response payload.
	NoTransform bool

	// Public is a boolean value that indicates whether the response is
	// considered public, meaning it can be cached by any cache.
	Public bool

	// Private is a map of field-name to boolean values that indicates whether
	// the response is considered private, meaning it can only be cached by a cache
	// that is specific to a particular user.
	Private map[string]bool

	// PrivatePresent is a boolean value that indicates whether the private
	// directive was present in the response.
	PrivatePresent bool

	// ProxyRevalidate is a boolean value that indicates whether a cache must
	// revalidate a stored response on every request when the response was obtained
	// from a proxy cache.
	ProxyRevalidate bool

	// MaxAge is the maximum time in seconds that a response can be considered fresh.
	MaxAge int32

	// SMaxAge is the maximum time in seconds that a shared cache can consider
	// a response to be fresh.
	SMaxAge int32

	// Immutable is a boolean value that indicates whether the response payload
	// is considered immutable and can be cached indefinitely.
	Immutable bool

	// StaleIfError is the maximum time in seconds that a cache can serve a stale
	// response when an error occurs.
	StaleIfError int32

	// StaleWhileRevalidate is the maximum time in seconds that a cache can serve
	// a stale response while a background revalidation is being performed.
	StaleWhileRevalidate int32

	// Extensions is a list of cache-extension tokens with optional values
	// that can be used to extend the Cache-Control header field.
	Extensions []string
}

func NewResponseCacheDirective

func NewResponseCacheDirective(value string) (*ResponseCacheDirective, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL