set

Function set 

Source
pub fn set<E: Encode>(
    key: impl AsRef<[u8]>,
    value: E,
    ttl: Duration,
) -> Result<(), CacheSetError<E::Error>>
Expand description

Set a value in the cache with a time-to-live.

Examples:


Bytes:


cache::set(
    "my_key",
    b"hello".to_vec(),
    Duration::from_secs(60),
)?;

Json:

use momento_functions_host::encoding::Json;

#[derive(serde::Serialize)]
struct MyStruct {
   hello: String
}

cache::set(
    "my_key",
    Json(MyStruct { hello: "hello".to_string() }),
    Duration::from_secs(60),
)?;