---
title: TransactionInsertBuilder
summary: A builder-style API for configuring a transactional cache insertion.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.TransactionInsertBuilder/
---

**Kind:** Struct  
**Module:** [core](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1085

```rust
pub struct TransactionInsertBuilder { /* private fields */ }
```

A builder-style API for configuring a transactional cache insertion.

## Methods

### deliver_node_max_age

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1142

```rust
fn deliver_node_max_age(self, duration: Duration) -> Self
```

Sets the maximum time the cached item may live on a deliver node in a POP.

**Parameters**

- `self`: `Self`
- `duration`: `Duration`

**Returns**

`Self`

### execute

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1158

```rust
fn execute(self) -> Result<StreamingBody, CacheError>
```

Begin the insertion, returning a [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) for providing the cached object itself.

For the insertion to complete successfully, the object must be written into the [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/),
and then [`StreamingBody::finish`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish) must be called. If the [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) is dropped before calling
[`StreamingBody::finish`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish), the insertion is considered incomplete, and any concurrent lookups that
may be reading from the object as it is streamed into the cache may encounter a streaming error.

**Parameters**

- `self`: `Self`

**Returns**

`Result<StreamingBody, CacheError>`

### execute_and_stream_back

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1174

```rust
fn execute_and_stream_back(self) -> Result<(StreamingBody, Found), CacheError>
```

Begin the insertion, and provide a `Found` object that can be used to stream out of the
newly-inserted object.

For the insertion to complete successfully, the object must be written into the [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/),
and then [`StreamingBody::finish`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish) must be called. If the [`StreamingBody`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/) is dropped before calling
[`StreamingBody::finish`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/body/struct.StreamingBody/#method-finish), the insertion is considered incomplete, and any concurrent lookups that
may be reading from the object as it is streamed into the cache may encounter a streaming error.

The returned [`Found`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Found/) object allows the client inserting a cache item to efficiently read
back the contents of that item, avoiding the need to buffer contents for copying to multiple
destinations. This pattern is commonly required when caching an item that also must be
provided to, e.g., the client response.

**Parameters**

- `self`: `Self`

**Returns**

`Result<(StreamingBody, Found), CacheError>`

### initial_age

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1106

```rust
fn initial_age(self, age: Duration) -> Self
```

Sets the initial age of the cached item, to be used in freshness calculations.

The initial age is `Duration::ZERO` by default.

**Parameters**

- `self`: `Self`
- `age`: `Duration`

**Returns**

`Self`

### known_length

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1124

```rust
fn known_length(self, length: u64) -> Self
```

Sets the size of the cached item, in bytes, when known prior to actually providing the bytes.

It is preferable to provide a length, if possible. Clients that begin streaming the item's
contents before it is completely provided will see the promised length which allows them to,
for example, use `content-length` instead of `transfer-encoding: chunked` if the item is
used as the body of a [`Request`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/) or [`Response`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/struct.Response/).

**Parameters**

- `self`: `Self`
- `length`: `u64`

**Returns**

`Self`

### on_behalf_of

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1150

```rust
fn on_behalf_of(self, service: impl ToString) -> Self
```

Perform this insertion on behalf of another service, using its data store.

#### Internal / Privileged

This operation is privileged, and attempts to use this functionality without
proper privileges will cause errors. If you are interested in having two or
more of your services share the same cache, please talk to your Fastly account
representative. While we have no plans to offer this ability widely -- this
capability is only currently allowed for Fastly-internal services -- we may
revisit this decision given sufficient customer input.

**Parameters**

- `self`: `Self`
- `service`: `impl ToString`

**Returns**

`Self`

### sensitive_data

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1136

```rust
fn sensitive_data(self, is_sensitive_data: bool) -> Self
```

Enable or disable PCI/HIPAA-compliant non-volatile caching.

By default, this is `false`

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

**Parameters**

- `self`: `Self`
- `is_sensitive_data`: `bool`

**Returns**

`Self`

### stale_while_revalidate

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1112

```rust
fn stale_while_revalidate(self, duration: Duration) -> Self
```

Sets the stale-while-revalidate period for the cached item, which is the time for which
the item can be safely used despite being considered stale.

Having a stale-while-revalidate period provides a signal that the cache should be updated
(or its contents otherwise revalidated for freshness) asynchronously, while the stale cached
item continues to be used, rather than blocking on updating the cached item. The methods
[`Found::is_usable`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Found/#method-is_usable) and [`Found::is_stale`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.Found/#method-is_stale) can be used to determine the current state of
a found item.

The stale-while-revalidate period is `Duration::ZERO` by default.

**Parameters**

- `self`: `Self`
- `duration`: `Duration`

**Returns**

`Self`

### surrogate_keys

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1118

```rust
fn surrogate_keys<'a>(self, keys: impl IntoIterator<Item = &'a str>) -> Self
```

Sets the surrogate keys that can be used for purging this cached item.

[Surrogate key purges](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/purge/fn.purge_surrogate_key/) 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 performing a
[purge-all](https://developer.fastly.com/learning/concepts/purging/#purge-all),
waiting for the item's TTL to elapse, or overwriting the item with
[`crate::cache::core::insert()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/fn.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](https://docs.fastly.com/en/guides/purging-api-cache-with-surrogate-keys)
for details.

**Parameters**

- `self`: `Self`
- `keys`: `impl IntoIterator<Item = &'a str>`

**Returns**

`Self`

### user_metadata

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1130

```rust
fn user_metadata(self, user_metadata: Bytes) -> Self
```

Sets the user-defined metadata to associate with the cached item.

**Parameters**

- `self`: `Self`
- `user_metadata`: `Bytes`

**Returns**

`Self`

### vary_by

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/cache/core.rs#1098

```rust
fn vary_by<'a>(self, headers: impl IntoIterator<Item = &'a HeaderName>) -> Self
```

Sets the list of headers that must match when looking up this cached item.

The header values must be provided by calling [TransactionLookupBuilder::header()](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.TransactionLookupBuilder/#method-header) or
[TransactionLookupBuilder::header_values()](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.TransactionLookupBuilder/#method-header_values).  The header values may be a subset or superset
of the header names supplied here.

**Note**: These headers are narrowly useful for implementing cache lookups
incorporating the semantics of the [HTTP `Vary`
header](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.5), but the APIs in
this module are not suitable for HTTP caching out-of-the-box. Future SDK
releases will contain an HTTP Cache API.

The headers act as additional factors in object selection, and the choice of _which_
headers to factor in is determined during insertion, via e.g.
[`crate::cache::core::InsertBuilder::vary_by`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/cache/core/struct.InsertBuilder/#method-vary_by). A lookup will succeed when there is at least one
cached item that matches lookup's cache key, and all of the lookup's headers included in the cache
items' `vary_by` list match the corresponding headers in that cached item.

A [typical example](https://www.fastly.com/blog/best-practices-using-vary-header)
is a cached HTTP response, where the request had an `Accept-Encoding` header. In that case,
the origin server may or may not decide on a given encoding, and whether that same response is
suitable for a request with a different (or missing) `Accept-Encoding` header is determined
by whether `Accept-Encoding` is listed in `Vary` header in the origin's response.

**Parameters**

- `self`: `Self`
- `headers`: `impl IntoIterator<Item = &'a HeaderName>`

**Returns**

`Self`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `Downcast`
- `DowncastSync`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `TryFrom<U>`
- `TryInto<U>`
