InsertBuilder

Structin kv_storefastly 0.13.1View source
pub struct InsertBuilder<'a> { /* private fields */ }

A builder for KVStore insertions, supporting advanced configuration like InsertMode, backgroundfetch, ifgeneration_match, metadata, ttl, and asynchronous execution.

store.build_insert()
.mode(InsertMode::Prepend)
.background_fetch()
.if_generation_match(1337)
.metadata("2000B of arbitrary data")
.time_to_live(std::time::Duration::from_secs(5))
.execute("key1", "value1")?;

Synchronous and Asynchronous support

InsertBuilder also exposes the ability to issue an asynchronous insert. When finalizing the InsertBuilder, execute_async will send the request, and unblock. There is currently no polling mechanism. To retrieve the result, use the blocking function pending_insert_wait.

Examples

// synchronous non-builder insert
let result: Result<(), KVStoreError> = store.insert("key", "value");
// synchronous builder insert
let result: Result<(), KVStoreError> = store.build_insert().execute("key", "value");
// asynchronous builder insert
let insert_handle: Result<PendingInsertHandle, KVStoreError> = store.build_insert().execute_async("key", "value");
let result: Result<(), KVStoreError> = store.pending_insert_wait(insert_handle?);

Methods

background_fetch

View source
fn background_fetch(self) -> Self

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.

Parameters

self: Self

Returns

Self
fn execute(self, key: &str, value: impl Into<Body>) -> Result<(), KVStoreError>

Initiate and wait on an insert of a value into the KV Store.

Returns Ok(()) if the value is inserted, and KVStoreError if the insert failed.

Parameters

self: Self
key: &str
value: impl Into<Body>

Returns

Result<(), KVStoreError>

execute_async

View source
fn execute_async(&self, key: &str, value: impl Into<Body>) -> Result<PendingInsertHandle, KVStoreError>

Initiate async insert of a value into the KV Store.

Returns Ok(Some(PendingInsertHandle)) if insert creation is successful.

Parameters

self: &Self
key: &str
value: impl Into<Body>

Returns

Result<PendingInsertHandle, KVStoreError>

if_generation_match

View source
fn if_generation_match(self, gen: u64) -> Self

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

self: Self
gen: u64

Returns

Self

metadata

View source
fn metadata(self, data: &str) -> Self

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

Parameters

self: Self
data: &str

Returns

Self
fn mode(self, mode: InsertMode) -> Self

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

Parameters

self: Self
mode: InsertMode

Returns

Self

time_to_live

View source
fn time_to_live(self, ttl: Duration) -> Self

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

Parameters

self: Self
ttl: std::time::Duration

Returns

Self

Auto trait implementations

Blanket implementations