CandidateResponse
type CandidateResponse struct { // contains filtered or unexported fields}CandidateResponse is a response from a backend that is a candidate for caching.
Methods
Age
View sourcefunc (candidateResponse *CandidateResponse) Age() (uint32, error)Age returns current age in seconds of the cached item, relative to the originating backend.
Returns
BodyTransform
View sourcefunc (candidateResponse *CandidateResponse) BodyTransform() func(io.ReadCloser) io.ReadCloserBodyTransform returns the current body transformation function.
Returns
DelHeader
View sourcefunc (candidateResponse *CandidateResponse) DelHeader(key string) errorDelHeader deletes a header from the candidate response.
Parameters
- key: string
Returns
Header
View sourcefunc (candidateResponse *CandidateResponse) Header(key string) (string, error)Header gets a header from the candidate response.
Parameters
- key: string
Returns
IsStale
View sourcefunc (candidateResponse *CandidateResponse) IsStale() (bool, error)IsStale returns whether the cached response is stale.
A cached response is stale if it has been in the cache beyond its TTL period.
Returns
MaxAge
View sourcefunc (candidateResponse *CandidateResponse) MaxAge() (uint32, error)MaxAge returns the duration of "freshness", in seconds, for the cached response after it is inserted into the cache.
This is the full freshness lifetime of the object: it does not subtract the time the object has already spent in cache (its age). Use TTLRemaining to find out how much freshness is left right now.
Returns
Sensitive
View sourcefunc (candidateResponse *CandidateResponse) Sensitive() (bool, error)Sensitive returns whether this response should only be stored via PCI/HIPAA-compliant non-volatile caching.
See the Fastly PCI-Compliant Caching and Delivery documentation for details.
Returns
SetBodyTransform
View sourcefunc (candidateResponse *CandidateResponse) SetBodyTransform(fn func(io.ReadCloser) io.ReadCloser)SetBodyTransform sets a callback to be used for transforming the response body prior to caching.
Body transformations are performed via a callback, rather than by directly working with the body, because not every response contains a fresh body: 304 Not Modified responses, which are used to revalidate a stale cached response, are valuable precisely because they do not retransmit the body.
For any other response status, the backend response will contain a relevant
body, and the transform callback will be invoked to return a new
io.ReadCloser for the transformed body.
Parameters
- fn: func(io.ReadCloser) io.ReadCloser
SetCacheable
View sourcefunc (candidateResponse *CandidateResponse) SetCacheable()SetCacheable marks the response as cacheable.
Forces this response to be stored in the cache, even if its headers or status would normally prevent that.
SetHeader
View sourcefunc (candidateResponse *CandidateResponse) SetHeader(key string, value string) errorSetHeader sets a header on the candidate response.
Parameters
- key: string
- value: string
Returns
SetSensitive
View sourcefunc (candidateResponse *CandidateResponse) SetSensitive(sensitive bool)SetSensitive sets the caching behavior of this response to enable or disable PCI/HIPAA-compliant non-volatile caching.
By default, this is false, which means the response may not be PCI/HIPAA-compliant. Set it
to true to enable compliant caching.
See the Fastly PCI-Compliant Caching and Delivery documentation) for details.
Parameters
- sensitive: bool
SetStaleIfError
View sourcefunc (candidateResponse *CandidateResponse) SetStaleIfError(sie uint32)SetStaleIfError sets the time in seconds for which a cached item can be delivered stale if synchronous revalidation produces an error.
Parameters
- sie: uint32
SetStaleWhileRevalidate
View sourcefunc (candidateResponse *CandidateResponse) SetStaleWhileRevalidate(swr uint32)SetStaleWhileRevalidate sets the time in seconds for which a cached item can safely be used despite being considered stale.
Parameters
- swr: uint32
SetStatus
View sourcefunc (candidateResponse *CandidateResponse) SetStatus(status int) errorSetStatus sets the HTTP Status of the candidate response.
Parameters
- status: int
Returns
SetSurrogateKeys
View sourcefunc (candidateResponse *CandidateResponse) SetSurrogateKeys(keys string)SetSurrogateKeys sets the surrogate keys for the cached response.
Surrogate keys must contain only printable ASCII characters (those between 0x21 and
0x7E, inclusive). Any invalid keys will be ignored.
See the Fastly surrogate keys guide for details.
Parameters
- keys: string
SetTTL
View sourcefunc (candidateResponse *CandidateResponse) SetTTL(ttl uint32)SetTTL sets the Time to Live (TTL) in seconds in the cache for this response.
The TTL determines the duration of "freshness" for the cached response after it is inserted into the cache.
Parameters
- ttl: uint32
SetUncacheable
View sourcefunc (candidateResponse *CandidateResponse) SetUncacheable()SetUncacheable marks the response as not to be stored in the cache.
See the Fastly request collapsing guide for more details on the mechanism
that recordUncacheable disables.
SetUncacheableDisableCollapsing
View sourcefunc (candidateResponse *CandidateResponse) SetUncacheableDisableCollapsing()SetUncacheableDisableCollapsing marks the response as not to be stored in the cache due to being an uncacheable response.
Future cache lookups will result in immediately going to the backend, rather than attempting to coordinate concurrent requests to reduce backend traffic.
See the Fastly request collapsing guide for more details on the mechanism
that recordUncacheable disables.
SetVary
View sourcefunc (candidateResponse *CandidateResponse) SetVary(vary string)SetVary sets the set of request headers for which the response may vary.
Parameters
- vary: string
StaleIfError
View sourcefunc (candidateResponse *CandidateResponse) StaleIfError() (uint32, error)StaleIfError returns the time in seconds for which a cached item will be delivered stale if synchronous revalidation produces an error.
Returns
StaleIfErrorAvailable
View sourcefunc (candidateResponse *CandidateResponse) StaleIfErrorAvailable() boolReturns whether there is a stale-if-error response available from the cache.
A CandidateResponse represents an HTTP response returned from a Backend. However, it may be preferable to return a cached response rather than the Backend's response -- for instance, if the Backend's response is a 5xx error.
This method returns true if there is a cached response that is within the stale-if-error period. If a stale-if-error response is available, and obtaining a response from the Backend fails -- because the BeforeSend or AfterSend hook returns an error, or because the request to the Backend itself fails -- the Request.Send call will return the stale-if-error response instead of the error.
Returns
StaleWhileRevalidate
View sourcefunc (candidateResponse *CandidateResponse) StaleWhileRevalidate() (uint32, error)StaleWhileRevalidate returns the time in seconds for which a cached item can safely be used despite being considered stale.
Returns
Status
View sourcefunc (candidateResponse *CandidateResponse) Status() (int, error)Status gets the status of the candidate response.
Returns
SurrogateKeys
View sourcefunc (candidateResponse *CandidateResponse) SurrogateKeys() (string, error)SurrogateKeys returns the surrogate keys for the cached response.
Returns
func (candidateResponse *CandidateResponse) TTL() (uint32, error)TTL returns the remaining Time to Live (TTL) in seconds in the cache for this response.
The TTL determines the duration of "freshness" for the cached response after it is inserted into the cache.
Deprecated: use TTLRemaining or MaxAge. The name TTL does not make clear whether it reports the full freshness lifetime of the object or the remaining freshness; it returns the remaining freshness (TTLRemaining).
Returns
TTLRemaining
View sourcefunc (candidateResponse *CandidateResponse) TTLRemaining() (uint32, error)TTLRemaining returns the remaining "freshness", in seconds, of the cached response: how much longer the object stays fresh from now.
This is the object's full freshness lifetime (MaxAge) minus the time it has already spent in cache (its age). When the object is already stale (its age meets or exceeds its full lifetime) the remaining freshness is reported as 0 rather than wrapping around.
Returns
Vary
View sourcefunc (candidateResponse *CandidateResponse) Vary() (string, error)Vary returns the set of request headers for which the response may vary.
Returns