InsertBuilder
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 insertlet result: Result<(), KVStoreError> = store.insert("key", "value");// synchronous builder insertlet result: Result<(), KVStoreError> = store.build_insert().execute("key", "value");// asynchronous builder insertlet 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 sourcefn background_fetch(self) -> SelfIf 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
execute
View sourceInitiate 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
Returns
execute_async
View sourceInitiate async insert of a value into the KV Store.
Returns Ok(Some(PendingInsertHandle)) if insert creation is successful.
Parameters
Returns
if_generation_match
View sourcefn if_generation_match(self, gen: u64) -> SelfRequests 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
metadata
View sourcefn metadata(self, data: &str) -> SelfSets an arbitrary data field which can contain up to 2000B of data.
Parameters
- self: Self
- data: &str
Returns
mode
View sourceChange the behavior in the case when the new key matches an existing key.
Parameters
- self: Self
- mode: InsertMode
Returns
time_to_live
View sourceSets 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