envelope
Module[Envelope]: the timestamped record the hash-based adapters store.
Contents
use utopia_cache::Envelope;Rust
pub struct Envelope<C>The {"time": <unix>, "data": <value>} record the Redis, Redis Cluster
and Hazelcast adapters store, run through a Codec. Encoding adds the
timestamp; decoding enforces the TTL against a caller-supplied now.
Rust
use php_std::types::Value;
use utopia_cache::{Envelope, Json};
let envelope = Envelope::new(Json);
let stored = envelope.encode(&Value::from("hello"), 1_700_000_000)?;
assert_eq!(stored, br#"{"time":1700000000,"data":"hello"}"#);
// Fresh while `time + ttl > now`.
assert_eq!(envelope.decode(&stored, 60, 1_700_000_059), Some(Value::from("hello")));
assert_eq!(envelope.decode(&stored, 60, 1_700_000_060), None);