pub fn insert(key: CacheKey, ttl: Duration) -> InsertBuilder
Expand description
Returns an InsertBuilder
that will perform a non-transactional cache insertion.
The required ttl
argument is the “time to live” for the cache item: the time for which the
item will be considered fresh. 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()
.unwrap();
writer.write_all(contents).unwrap();
writer.finish().unwrap();
§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
.