---
title: CandidateResponse
summary: CandidateResponse is a response from a backend that is a candidate for caching.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.CandidateResponse/
---

**Kind:** Struct  
**Module:** [fsthttp](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L18

```go
type CandidateResponse struct {
	// contains filtered or unexported fields
}
```

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

## Methods

### Age

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L408

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L623

```go
func (candidateResponse *CandidateResponse) BodyTransform() func(io.ReadCloser) io.ReadCloser
```

BodyTransform returns the current body transformation function.

**Returns**

`func(io.ReadCloser) io.ReadCloser`

### DelHeader

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L322

```go
func (candidateResponse *CandidateResponse) DelHeader(key string) error
```

DelHeader deletes a header from the candidate response.

**Parameters**

- `key`: `string`

**Returns**

`error`

### Header

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L330

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

Header gets a header from the candidate response.

**Parameters**

- `key`: `string`

**Returns**

`(string, error)`

### IsStale

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L399

```go
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)`

### MaxAge

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L422

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L552

```go
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](https://docs.fastly.com/products/pci-compliant-caching-and-delivery) for details.

**Returns**

`(bool, error)`

### SetBodyTransform

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L618

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L342

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L314

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L542

```go
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](https://docs.fastly.com/products/pci-compliant-caching-and-delivery)) for details.

**Parameters**

- `sensitive`: `bool`

### SetStaleIfError

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L500

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L482

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L380

```go
func (candidateResponse *CandidateResponse) SetStatus(status int) error
```

SetStatus sets the HTTP Status of the candidate response.

**Parameters**

- `status`: `int`

**Returns**

`error`

### SetSurrogateKeys

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L589

```go
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](https://docs.fastly.com/en/guides/purging-api-cache-with-surrogate-keys) for details.

**Parameters**

- `keys`: `string`

### SetTTL

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L476

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L359

```go
func (candidateResponse *CandidateResponse) SetUncacheable()
```

SetUncacheable marks the response as not to be stored in the cache.

See the [Fastly request collapsing guide](https://www.fastly.com/documentation/guides/concepts/edge-state/cache/request-collapsing/) for more details on the mechanism
that `recordUncacheable` disables.

### SetUncacheableDisableCollapsing

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L374

```go
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](https://www.fastly.com/documentation/guides/concepts/edge-state/cache/request-collapsing/) for more details on the mechanism
that `recordUncacheable` disables.

### SetVary

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L564

```go
func (candidateResponse *CandidateResponse) SetVary(vary string)
```

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

**Parameters**

- `vary`: `string`

### StaleIfError

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L506

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L528

```go
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](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.Request/#method-Send) call will return the stale-if-error response
instead of the error.

**Returns**

`bool`

### StaleWhileRevalidate

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L488

```go
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)`

### Status

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L388

```go
func (candidateResponse *CandidateResponse) Status() (int, error)
```

Status gets the status of the candidate response.

**Returns**

`(int, error)`

### SurrogateKeys

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L595

```go
func (candidateResponse *CandidateResponse) SurrogateKeys() (string, error)
```

SurrogateKeys returns the surrogate keys for the cached response.

**Returns**

`(string, error)`

### TTL

**Flags:** deprecated  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L468

> **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).

```go
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

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L441

```go
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)`

### Vary

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/cache.go#L570

```go
func (candidateResponse *CandidateResponse) Vary() (string, error)
```

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

**Returns**

`(string, error)`
