get_or_set

Functionin simplefastly 0.13.1View source
fn get_or_set(key: impl Into<CacheKey>, value: impl Into<Body>, ttl: Duration) -> Result<Body, CacheError>

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))?;
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.

Parameters

key: impl Into<CacheKey>
value: impl Into<Body>
ttl: std::time::Duration

Returns