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

**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#L1045

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

A builder-style API for configuring a non-transactional cache replacement.

## Methods

### always_use_requested_range

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

```cpp
ReplaceBuilder fastly::cache::core::ReplaceBuilder::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**

`ReplaceBuilder`

### begin

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

```cpp
tl::expected<Replace, CacheError> fastly::cache::core::ReplaceBuilder::begin() &&
```

Begin the replace, returning a [`Replace`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Replace/) for reading the object to be replaced (if it exists) which is also used to provide the new replacement object.

A [`Replace`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Replace/) gives access to the existing object, if one is stored, that may be used to construct the replacement object. Use [`Replace::execute()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Replace/#method-execute) to get a `StreamingBody` to write the replacement object into. The existing object cannot be accessed after calling [`Replace::execute()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/core/class.Replace/#method-execute).

For the replace to complete successfully, the object must be written into the `StreamingBody`, and then `StreamingBody::finish` must be called. If the `StreamingBody` is dropped before calling `StreamingBody::finish`, the replacement 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.

**Returns**

`tl::expected<Replace, CacheError>`

### replace_strategy

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

```cpp
ReplaceBuilder fastly::cache::core::ReplaceBuilder::replace_strategy(ReplaceStrategy strategy) &&
```

Sets the strategy for performing the replace.

**Parameters**

- `strategy`: `ReplaceStrategy`

**Returns**

`ReplaceBuilder`
