Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v2.30.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheControlResponse

type CacheControlResponse struct {
	// MaxAge is the maximum age of the response in seconds.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.8
	//
	// The "max-age" response directive indicates that the response is to be
	// considered stale after its age is greater than the specified number of seconds.
	MaxAge *DeltaSeconds

	// SMaxAge is the maximum age of the response in seconds for shared caches.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.9
	//
	// The "s-maxage" response directive indicates that, in shared caches,
	// the maximum age specified by this directive overrides the maximum age
	// specified by either the max-age directive or the Expires header
	// field.
	//
	// The s-maxage directive also implies the semantics of the
	// proxy-revalidate response directive.
	SMaxAge *DeltaSeconds

	// NoStore indicates that a cache MUST NOT
	// store any part of either the immediate request or response.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.3
	//
	// This directive applies to both private and shared caches.
	// "MUST NOT store" in this context means that the cache MUST NOT intentionally
	// store the information in non-volatile storage, and MUST make a
	// best-effort attempt to remove the information from volatile storage
	// as promptly as possible after forwarding it.
	NoStore bool

	// NoCache is a list of field names that should not be cached.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.2
	//
	// The "no-cache" response directive indicates that the response MUST
	// NOT be used to satisfy a subsequent request without successful
	// validation on the origin server.
	//
	// This allows an origin server to prevent a cache from using it to satisfy a request without contacting
	// it, even by caches that have been configured to send stale responses.
	//
	// If the no-cache response directive specifies one or more field-names,
	// then a cache MAY use the response to satisfy a subsequent request,
	// subject to any other restrictions on caching.  However, any header
	// fields in the response that have the field-name(s) listed MUST NOT be
	// sent in the response to a subsequent request without successful
	// revalidation with the origin server.  This allows an origin server to
	// prevent the re-use of certain header fields in a response, while
	// still allowing caching of the rest of the response.
	NoCache *FieldNames

	// Public indicates that any cache MAY store the response,
	// even if the response would normally be non-cacheable or cacheable only within a private cache.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.5
	Public bool

	// Private indicates that the response message is intended for a single user and MUST NOT be stored by a shared cache.
	// A private cache MAY store the response and reuse it for later requests, even if the response would normally be non-cacheable.
	//
	// Defined in https://datatracker.ietf.org/doc/html/rfc7234#section-5.2.2.6
	//
	// If the private response directive specifies one or more field-names,
	// this requirement is limited to the field-values associated with the
	// listed response header fields. That is, a shared cache MUST NOT
	// store the specified field-names(s), whereas it MAY store the
	// remainder of the response message.
	Private *FieldNames

	// MustRevalidate requires stale responses to be revalidated.
	MustRevalidate bool

	// ProxyRevalidate applies must-revalidate to shared caches.
	ProxyRevalidate bool

	// StaleIfError allows a stale response after an origin error.
	StaleIfError *DeltaSeconds

	// StaleWhileRevalidate allows a stale response while revalidating it.
	StaleWhileRevalidate *DeltaSeconds
}

func ParseCacheControlResponse

func ParseCacheControlResponse(headers http.Header) (*CacheControlResponse, error)

func (*CacheControlResponse) HasCachingDirectives added in v2.20.3

func (c *CacheControlResponse) HasCachingDirectives() bool

HasCachingDirectives reports whether the response contained a recognized directive that affects caching.

func (*CacheControlResponse) ToHeaderString added in v2.19.0

func (c *CacheControlResponse) ToHeaderString() string

ToHeaderString converts a CacheControlResponse to a Cache-Control header string.

type DeltaSeconds

type DeltaSeconds int32

DeltaSeconds is a signed 32-bit integer representing the number of seconds. It is defined in https://datatracker.ietf.org/doc/html/rfc7234#section-1.2.1

The delta-seconds rule specifies a non-negative integer, representing time in seconds.

A recipient parsing a delta-seconds value and converting it to binary form ought to use an arithmetic type of at least 31 bits of non-negative integer range.

If a cache receives a delta-seconds value greater than the greatest integer it can represent, or if any of its subsequent calculations overflows, the cache MUST consider the value to be either 2147483648 (2^31) or the greatest positive integer it can conveniently represent.

func ToDeltaSeconds added in v2.19.0

func ToDeltaSeconds(d time.Duration) DeltaSeconds

ToDeltaSeconds converts a time.Duration to a DeltaSeconds.

func (DeltaSeconds) AsDuration

func (d DeltaSeconds) AsDuration() time.Duration

AsDuration converts a DeltaSeconds to a time.Duration.

func (DeltaSeconds) String added in v2.19.0

func (d DeltaSeconds) String() string

String converts a DeltaSeconds to a string.

type FieldNames

type FieldNames struct {
	// contains filtered or unexported fields
}

FieldNames is a map of field names.

func NewFieldNames

func NewFieldNames() *FieldNames

func (*FieldNames) Add

func (f *FieldNames) Add(name string)

func (*FieldNames) Fields

func (f *FieldNames) Fields() iter.Seq[string]

Fields returns an iterator over the field names.

Example:

 ```
 fields := NewFieldNames()
	fields.Add("field1")
	fields.Add("field2")

	for field := range f.Fields() {
		fmt.Println(field)
	}

```

func (*FieldNames) FieldsString added in v2.19.0

func (f *FieldNames) FieldsString() string

FieldsString returns the field names as a string. The string is wrapped in double quotes and comma-separated.

func (*FieldNames) LockFields

func (f *FieldNames) LockFields()

Jump to

Keyboard shortcuts

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