pub fn lookup(key: CacheKey) -> LookupBuilder
Expand description
Returns a LookupBuilder
that will perform a non-transactional cache lookup.
let mut cached_string = String::new();
if let Some(entry) = lookup(CacheKey::from_static(b"my_key")).execute().unwrap() {
entry
.to_stream()
.unwrap()
.read_to_string(&mut cached_string)
.unwrap();
}
println!("the cached string was: {cached_string}");
Relationship with Transaction::lookup()
In contrast to Transaction::lookup()
, a non-transactional lookup
will not attempt to
coordinate with any concurrent cache lookups. If two instances of the service perform a lookup
at the same time for the same cache key, and the item is not yet cached, they will both get
Ok(None)
from the eventual lookup execution. Without further coordination, they may both end
up performing the work needed to insert()
the item (which usually involves origin requests
and/or computation) and racing with each other to insert.
To resolve such races between concurrent lookups, use Transaction::lookup()
instead.