---
title: InsertBuilder
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/kv_store/class.InsertBuilder/
---

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

Include `fastly/kv_store.h` to use this class.

## Methods

### background_fetch

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L157

```cpp
InsertBuilder fastly::kv_store::InsertBuilder::background_fetch() &&
```

If set, allows fetching from the origin to occur in the background, enabling a faster response with stale content. The cache will be updated with fresh content after the request is completed.

**Returns**

`InsertBuilder`

### execute

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L175

```cpp
expected fastly::kv_store::InsertBuilder::execute(const std::string &key, Body body) &&
```

Initiate and wait on an insert of a value into the KV Store. The return object is engaged if the value was inserted, and [KVStoreError](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/kv_store/class.KVStoreError/) if the insert failed.

**Parameters**

- `key`: `const std::string &`
- `body`: `Body`

**Returns**

`expected`

### execute_async

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L178

```cpp
expected<PendingInsertHandle> fastly::kv_store::InsertBuilder::execute_async(const std::string &key, Body body) &&
```

Initiate async insert of a value into the KV Store.

**Parameters**

- `key`: `const std::string &`
- `body`: `Body`

**Returns**

`expected<PendingInsertHandle>`

### if_generation_match

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L163

```cpp
InsertBuilder fastly::kv_store::InsertBuilder::if_generation_match(std::uint64_t gen) &&
```

Requests for keys will return a ‘generation’ header specific to the version of a key. The generation header is a unique, non-serial 64-bit unsigned integer that can be used for testing against a specific KV store value.

**Parameters**

- `gen`: `std::uint64_t`

**Returns**

`InsertBuilder`

### metadata

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L166

```cpp
InsertBuilder fastly::kv_store::InsertBuilder::metadata(const std::string &data) &&
```

Sets an arbitrary data field which can contain up to 2000B of data.

**Parameters**

- `data`: `const std::string &`

**Returns**

`InsertBuilder`

### mode

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L152

```cpp
InsertBuilder fastly::kv_store::InsertBuilder::mode(InsertMode mode) &&
```

Change the behavior in the case when the new key matches an existing key.

**Parameters**

- `mode`: `InsertMode`

**Returns**

`InsertBuilder`

### time_to_live

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/kv_store.h#L170

```cpp
InsertBuilder fastly::kv_store::InsertBuilder::time_to_live(std::chrono::milliseconds ttl) &&
```

Sets a time for the key to expire. Deletion will take place up to 24 hours after the ttl reaches 0.

**Parameters**

- `ttl`: `std::chrono::milliseconds`

**Returns**

`InsertBuilder`
