StoredValue

Struct StoredValue 

Source
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>

Source

pub fn value_ref(&self) -> &Value

Returns a reference to the value stored inside Store

Source

pub fn key_id(&self) -> u64

Source

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

Source§

impl<Value> StoredValue<Value>
where Value: Clone,

Source

pub fn value(&self) -> Value

Returns the cloned value stored inside Store

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V