---
title: CacheOptions
summary: CacheOptions control caching behavior for outgoing requests.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/struct.CacheOptions/
---

**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/request.go#L1041

```go
type CacheOptions struct {
	Pass bool

	PCI bool

	TTL uint32

	StaleWhileRevalidate uint32

	StaleIfError uint32

	SurrogateKey string

	OverrideKey string

	LookupTimeout time.Duration

	BeforeSend func(*Request) error

	AfterSend func(*CandidateResponse) error
}
```

CacheOptions control caching behavior for outgoing requests.

## Fields

### Pass

**Type:** `bool`

Pass controls whether or not to force a request to bypass the cache.
By default this is false, which means the request will only reach the
backend if the request is not normally cacheable (such as a POST), or
if a cached response is not available. If pass is set to true, the
request will always be sent directly to the backend.

Setting Pass to false does not guarantee that a response will be
cached for this request, it only allows a caching attempt to be made.
For example, a `GET` request may appear cacheable, but if the backend
response contains `cache-control: no-store`, the response will not be
cached.

Pass is mutually exclusive with all other cache options. Setting any
other option will change Pass to false.

### PCI

**Type:** `bool`

PCI controls the PCI/HIPAA compliant, non-volatile caching of the
request. PCI is false by default, which means the request may not be
PCI/HIPAA compliant. If PCI is set to true, caching will be made
compliant, and the request will not be forced to bypass the cache.

https://docs.fastly.com/products/pci-compliant-caching-and-delivery

### TTL

**Type:** `uint32`

TTL represents a Time-to-Live for cached responses to the request, in
seconds. If greater than zero, it overrides any behavior specified in the
response headers, and the request will not be forced to bypass the cache.

### StaleWhileRevalidate

**Type:** `uint32`

StaleWhileRevalidate represents a stale-while-revalidate time for the
request, in seconds. If greater than zero, it overrides any behavior
specified in the response headers, and the request will not be forced to
bypass the cache.

### StaleIfError

**Type:** `uint32`

The maximum duration in seconds after `max_age` during which the response
may be delivered stale if synchronous revalidation produces an error.

If this field is not set, the default value is zero.

### SurrogateKey

**Type:** `string`

SurrogateKey represents an explicit surrogate key for the request, which
will be added to any `Surrogate-Key` response headers received from the
backend. If nonempty, the request will not be forced to bypass the cache.

https://docs.fastly.com/en/guides/purging-api-cache-with-surrogate-keys

### OverrideKey

**Type:** `string`

Cache key to use in lieu of the automatically-generated cache key based on the request's
properties.

### LookupTimeout

**Type:** `time.Duration`

LookupTimeout bounds how long this request will wait for a cache
lookup to resolve.

### BeforeSend

**Type:** `func(*Request) error`

Sets a callback to be invoked if a request is going all the way to a
backend, allowing the request to be modified beforehand.

This callback is useful when, for example, a backend requires an
additional header to be inserted, but that header is expensive to
produce. The callback will only be invoked if the original request
cannot be responded to from the cache, so the header is only computed
when it is truly needed.

NOTE: To enable BeforeSend the build tag fsthttp_guest_cache must be set.
Without it, the function will always return an error.

### AfterSend

**Type:** `func(*CandidateResponse) error`

Sets a callback to be invoked after a response is returned from a
backend, but before it is stored into the cache.

This callback allows for cache properties like TTL to be customized
beyond what the backend response headers specify. It also allows for the
response itself to be modified prior to storing into the cache.

NOTE: To enable AfterSend the build tag fsthttp_guest_cache must be set.
Without it, the function will always return an error.
