insert

Functionin corefastly 0.13.1View source
fn insert(key: CacheKey, max_age: Duration) -> InsertBuilder

Returns an InsertBuilder that will perform a non-transactional cache insertion.

The required max_age argument is the maximal "time to live" for the cache item: the time for which the item will be considered fresh, starting from the start of its history. (The start of history defaults to "now" unless initial_age is provided.) All other insertion arguments are optional, and may be set using the returned builder.

let contents = b"my cached object";
let mut writer = insert(CacheKey::from_static(b"my_key"), Duration::from_secs(3600))
.surrogate_keys(["my_key"])
.known_length(contents.len() as u64)
.execute()?;
writer.write_all(contents)?;
writer.finish()?;

Relationship with Transaction::lookup()

Like lookup(), insert() may race with concurrent lookups or insertions, and will unconditionally overwrite existing cached items rather than allowing for revalidation of an existing object.

The transactional equivalent of this function is Transaction::insert(), which may only be called following a transactional lookup when Transaction::must_insert_or_update() returns true.

Parameters

key: CacheKey
max_age: std::time::Duration

Returns