pub struct StoredValue<Value> { /* private fields */ }Expand description
StoredValue wraps the client provided Value and it is stored as a value in the crate::cache::store::Store.
It encapsulates the value, key_id, the optional expiry of the key.
and a flag to identify whether a key is soft deleted
It is relevant to the clients on the invocation of get_ref and map_get_ref methods on crate::cache::cached::CacheD.
use tinylfu_cached::cache::cached::CacheD;
use tinylfu_cached::cache::command::CommandStatus;
use tinylfu_cached::cache::config::ConfigBuilder;
#[tokio::main]
async fn main() {
let cached = CacheD::new(ConfigBuilder::new(100, 10, 100).build());
let status = cached.put("topic", "microservices").unwrap().handle().await;
assert_eq!(CommandStatus::Accepted, status);
let value = cached.get_ref(&"topic");
let value_ref = value.unwrap();
let stored_value = value_ref.value();
assert_eq!("microservices", stored_value.value());
}use tinylfu_cached::cache::cached::CacheD;
use tinylfu_cached::cache::command::CommandStatus;
use tinylfu_cached::cache::config::ConfigBuilder;
#[tokio::main]
async fn main() {
let cached = CacheD::new(ConfigBuilder::new(100, 10, 100).build());
let status = cached.put("topic", "microservices").unwrap().handle().await;
assert_eq!(CommandStatus::Accepted, status);
let value = cached.map_get_ref(&"topic", |stored_value| stored_value.value_ref().to_uppercase());
assert_eq!("MICROSERVICES", value.unwrap());
}Implementations§
Source§impl<Value> StoredValue<Value>
impl<Value> StoredValue<Value>
pub fn key_id(&self) -> u64
Sourcepub fn expire_after(&self) -> Option<SystemTime>
pub fn expire_after(&self) -> Option<SystemTime>
Returns the expiry of the key. It returns: None: if the expiry is not set Some: if the expiry is set
Auto Trait Implementations§
impl<Value> Freeze for StoredValue<Value>where
Value: Freeze,
impl<Value> RefUnwindSafe for StoredValue<Value>where
Value: RefUnwindSafe,
impl<Value> Send for StoredValue<Value>where
Value: Send,
impl<Value> Sync for StoredValue<Value>where
Value: Sync,
impl<Value> Unpin for StoredValue<Value>where
Value: Unpin,
impl<Value> UnwindSafe for StoredValue<Value>where
Value: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more