---
title: WriteOptions
summary: WriteOptions control the behavior of cache inserts and updates. TTL is required, but all other fields are optional.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/cache/core/struct.WriteOptions/
---

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

```go
type WriteOptions struct {
	TTL time.Duration

	RequestHeaders fsthttp.Header

	Vary []string

	InitialAge time.Duration

	StaleWhileRevalidate time.Duration

	SurrogateKeys []string

	Length uint64

	UserMetadata []byte

	SensitiveData bool
}
```

WriteOptions control the behavior of cache inserts and updates.  TTL
is required, but all other fields are optional.

## Fields

### TTL

**Type:** `time.Duration`

TTL is the maximum time the cached object will be considered
fresh.  Required.

### RequestHeaders

**Type:** `fsthttp.Header`

RequestHeaders are a set of HTTP headers that influence cache
lookups when Vary rules are set.

This field is only valid for Insert outside of a transaction.  If
provided to Insert or Update inside a transaction,
ErrInvalidArgument will be returned.

### Vary

**Type:** `[]string`

Vary is a list of HTTP header names (provided in RequestHeaders)
that must match when looking up this key.

### InitialAge

**Type:** `time.Duration`

InitialAge is the initial age of the cached object.

### StaleWhileRevalidate

**Type:** `time.Duration`

StaleWhileRevalidate is the period of time in which the cached
object can be served stale while revalidation is taking place.

This provides a signal that the cache should be updated (or its
contents otherwise revalidated for freshness) asynchronously,
while the stale cached object continues to be used, rather than
blocking on updating the cached object.  The methods Usable and
Stale can be used to determine the current state of a found item.

### SurrogateKeys

**Type:** `[]string`

SurrogateKeys is a list of surrogate keys which can be used to
purge this object.

Surrogate key purges are the only means to purge specific items
from the cache.  At least one surrogate key must be set in order
to remove an item without performaing a purge-all, waiting for
the item's TTL to elapse, or overwriting the item with Insert.

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:
https://docs.fastly.com/en/guides/purging-api-cache-with-surrogate-keys

### Length

**Type:** `uint64`

Length sets the size of the cached object, in bytes, when known
prior to actually providing the bytes.

It is preferable to provide a length, if possible.  Clients that
begin streaming the object's contents before it is completely
provided will see the promised length which allows them to, for
example, use Content-Length instead of chunked Transfer-Encoding
if the item is used as the body of an HTTP request or response.

### UserMetadata

**Type:** `[]byte`

UserMetadata is abitrary user-provided metadata that will be
associated with the cached object.

### SensitiveData

**Type:** `bool`

SensitiveData indiciates whether to enable PCI/HIPAA-compliant
non-volatile caching.

See the Fastly PCI-Compliant Caching and Delivery documentation
for details:
https://docs.fastly.com/products/pci-compliant-caching-and-delivery
