CacheOptions

Structin fsthttpcompute-sdk-go v1.10.0View source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type CacheOptions struct {
Pass bool
PCI bool
TTL uint32
StaleWhileRevalidate uint32
StaleIfError uint32
SurrogateKey string
OverrideKey string
BeforeSend func(*Request) error
AfterSend func(*CandidateResponse) error
}

CacheOptions control caching behavior for outgoing requests.

Fields

Pass

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

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

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

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

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

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

string

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

BeforeSend

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 fsthttpguestcache must be set. Without it, the function will always return an error.

AfterSend

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 fsthttpguestcache must be set. Without it, the function will always return an error.