CandidateResponse

Structin fsthttpcompute-sdk-go v1.11.0View source
type CandidateResponse struct {
// contains filtered or unexported fields
}

CandidateResponse is a response from a backend that is a candidate for caching.

Methods

func (candidateResponse *CandidateResponse) Age() (uint32, error)

Age returns current age in seconds of the cached item, relative to the originating backend.

Returns

(uint32, error)

BodyTransform

View source
func (candidateResponse *CandidateResponse) BodyTransform() func(io.ReadCloser) io.ReadCloser

BodyTransform returns the current body transformation function.

Returns

func(io.ReadCloser) io.ReadCloser

DelHeader

View source
func (candidateResponse *CandidateResponse) DelHeader(key string) error

DelHeader deletes a header from the candidate response.

Parameters

key: string

Returns

error
func (candidateResponse *CandidateResponse) Header(key string) (string, error)

Header gets a header from the candidate response.

Parameters

key: string

Returns

(string, error)
func (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

(bool, error)
func (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

(uint32, error)

Sensitive

View source
func (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

(bool, error)

SetBodyTransform

View source
func (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 source
func (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 source
func (candidateResponse *CandidateResponse) SetHeader(key string, value string) error

SetHeader sets a header on the candidate response.

Parameters

key: string
value: string

Returns

error

SetSensitive

View source
func (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 source
func (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 source
func (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 source
func (candidateResponse *CandidateResponse) SetStatus(status int) error

SetStatus sets the HTTP Status of the candidate response.

Parameters

status: int

Returns

error

SetSurrogateKeys

View source
func (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
func (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 source
func (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 source
func (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.

func (candidateResponse *CandidateResponse) SetVary(vary string)

SetVary sets the set of request headers for which the response may vary.

Parameters

vary: string

StaleIfError

View source
func (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

(uint32, error)

StaleIfErrorAvailable

View source
func (candidateResponse *CandidateResponse) StaleIfErrorAvailable() bool

Returns 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

bool

StaleWhileRevalidate

View source
func (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

(uint32, error)
func (candidateResponse *CandidateResponse) Status() (int, error)

Status gets the status of the candidate response.

Returns

(int, error)

SurrogateKeys

View source
func (candidateResponse *CandidateResponse) SurrogateKeys() (string, error)

SurrogateKeys returns the surrogate keys for the cached response.

Returns

(string, error)

TTL

deprecatedView source
Deprecated: 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).
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

(uint32, error)

TTLRemaining

View source
func (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

(uint32, error)
func (candidateResponse *CandidateResponse) Vary() (string, error)

Vary returns the set of request headers for which the response may vary.

Returns

(string, error)