pub struct Cache<D: Driver> { /* private fields */ }
Expand description
Unified cache interface.
Implementations§
source§impl<D: Driver> Cache<D>
impl<D: Driver> Cache<D>
sourcepub async fn has(&self, key: &str) -> Result<bool, D::Error>
pub async fn has(&self, key: &str) -> Result<bool, D::Error>
Check if an item exists in the cache.
Errors
Returns an error if the driver fails to check if the item exists.
sourcepub async fn remember<T: Serialize + DeserializeOwned + Send + Sync>(
&mut self,
key: &str,
duration: Duration,
value: T
) -> Result<T, D::Error>
pub async fn remember<T: Serialize + DeserializeOwned + Send + Sync>( &mut self, key: &str, duration: Duration, value: T ) -> Result<T, D::Error>
Retrieve an item from the cache, or store it for some time if it doesn’t exist yet.
Errors
Returns an error if the driver fails to retrieve or store the item.
sourcepub async fn remember_forever<T: Serialize + DeserializeOwned + Send + Sync>(
&mut self,
key: &str,
value: T
) -> Result<T, D::Error>
pub async fn remember_forever<T: Serialize + DeserializeOwned + Send + Sync>( &mut self, key: &str, value: T ) -> Result<T, D::Error>
Retrieve an item from the cache, or store it forever if it doesn’t exist yet.
Errors
Returns an error if the driver fails to retrieve or store the item.
sourcepub async fn pull<T: DeserializeOwned + Send>(
&mut self,
key: &str
) -> Result<Option<T>, D::Error>
pub async fn pull<T: DeserializeOwned + Send>( &mut self, key: &str ) -> Result<Option<T>, D::Error>
Remove an item from the cache and return it.
Errors
Returns an error if the driver fails to retrieve or remove the item.
sourcepub async fn put<T: Serialize + Sync>(
&mut self,
key: &str,
value: &T,
expiry: Duration
) -> Result<(), D::Error>
pub async fn put<T: Serialize + Sync>( &mut self, key: &str, value: &T, expiry: Duration ) -> Result<(), D::Error>
Store an item in the cache for a given duration.
Errors
Returns an error if the driver fails to store the item.
sourcepub async fn add<T: Serialize + Send + Sync>(
&mut self,
key: &str,
value: T,
expiry: Duration
) -> Result<bool, D::Error>
pub async fn add<T: Serialize + Send + Sync>( &mut self, key: &str, value: T, expiry: Duration ) -> Result<bool, D::Error>
Store an item in the cache if it doesn’t exist yet.
Errors
Returns an error if the driver fails to store the item.
sourcepub async fn forever<T: Serialize + Send + Sync>(
&mut self,
key: &str,
value: T
) -> Result<(), D::Error>
pub async fn forever<T: Serialize + Send + Sync>( &mut self, key: &str, value: T ) -> Result<(), D::Error>
Store an item in the cache indefinitely.
Errors
Returns an error if the driver fails to store the item.