---
title: TransactionLookupBuilder
summary: A builder-style API for configuring a transactional cache lookup.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.TransactionLookupBuilder/
---

**Kind:** Class  
**Module:** [core](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/)  
**Package:** compute-sdk-cpp 0.7.0  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L414

Include `fastly/cache/core.h` to use this class.

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

## Methods

### always_use_requested_range

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L506

```cpp
TransactionLookupBuilder fastly::cache::core::TransactionLookupBuilder::always_use_requested_range() &&
```

Respect the range in to_stream_with_range even when the body length is not yet known.

When a cache item is [Found](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Found/), the length of the cached item may or may not be known:

- the item may be fully cached;
- the item may be streaming in, but have a known length; or
- the item may be streaming in progressively, without a known length.

By default (legacy behavior), if a range is specified but the length is not known, the contents of the entire item will be provided instead of the requested range.

always_use_requested_range indicates any cached item returned by this lookup should provide only the requested range, regardless of whether the length is known. An invalid range will eventually return a read error, possibly after providing some data.

NOTE: In the future, the always_use_requested_range behavior will be the default, and this method will be removed.

**Returns**

`TransactionLookupBuilder`

### execute

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L512

```cpp
tl::expected<Transaction, CacheError> fastly::cache::core::TransactionLookupBuilder::execute() &&
```

Perform the lookup, entering a [`Transaction`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Transaction/).

If the lookup hits an object being provided by another client, this call will block until that client provides the object's metadata or cancels.

**Returns**

`tl::expected<Transaction, CacheError>`

### execute_async

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L520

```cpp
tl::expected<PendingTransaction, CacheError> fastly::cache::core::TransactionLookupBuilder::execute_async() &&
```

Perform the lookup, returning a [`PendingTransaction`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.PendingTransaction/).

If the lookup hits an object being provided by another client, this call will not block. Instead, the returned [`PendingTransaction`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.PendingTransaction/) can be used to wait for the request collapsed lookup to complete. See the documentation of [`PendingTransaction`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.PendingTransaction/) for more details.

**Returns**

`tl::expected<PendingTransaction, CacheError>`

### header

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L467

```cpp
TransactionLookupBuilder fastly::cache::core::TransactionLookupBuilder::header(std::string_view name, const http::HeaderValue &value) &&
```

Sets a single-value header for this lookup, discarding any previous values associated with the header `name`. Note: These headers are narrowly useful for implementing cache lookups incorporating the semantics of the [HTTP Vary](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.5) header, 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`. 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 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**

- `name`: `std::string_view`
- `value`: `const http::HeaderValue &`

**Returns**

`TransactionLookupBuilder`

### header_values

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L439

```cpp
TransactionLookupBuilder fastly::cache::core::TransactionLookupBuilder::header_values(std::string_view name, std::span<const http::HeaderValue> values) &&
```

Sets a multi-value header for this lookup, discarding any previous values associated with the header name.

Note: These headers are narrowly useful for implementing cache lookups incorporating the semantics of the [HTTP Vary](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.5) header, 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`. 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 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**

- `name`: `std::string_view`
- `values`: `std::span<const http::HeaderValue>`

**Returns**

`TransactionLookupBuilder`

### on_behalf_of

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/core.h#L482

```cpp
TransactionLookupBuilder fastly::cache::core::TransactionLookupBuilder::on_behalf_of(std::string service) &&
```

Perform this lookup 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**

- `service`: `std::string`

**Returns**

`TransactionLookupBuilder`
