Function fastly::cache::simple::get_or_set

source ·
pub fn get_or_set(
    key: impl Into<CacheKey>,
    value: impl Into<Body>,
    ttl: Duration
) -> Result<Body, CacheError>
Expand description

Get the entry associated with the given cache key if it exists, or insert and return the specified entry.

If the value is costly to compute, consider using get_or_set_with() instead to avoid computation in the case where the value is already present.

let value = get_or_set("my_key", "hello!", Duration::from_secs(60)).unwrap();
let cached_string = value.into_string();
println!("the cached string was: {cached_string}");

§Argument type conversions

See the From impls for Bytes and Body to see which types can be used as a key or a body, respectively.