pub struct ProviderCache {
pub cache: Arc<Mutex<HashMap<String, CacheEntry>>>,
}Expand description
Global cache for provider results with automatic cleanup
Fields§
§cache: Arc<Mutex<HashMap<String, CacheEntry>>>Implementations§
Source§impl ProviderCache
impl ProviderCache
Sourcepub fn get_with_options<T: Clone + Send + Sync + 'static>(
&self,
key: &str,
options: CacheGetOptions,
) -> Option<CacheGetResult<T>>
pub fn get_with_options<T: Clone + Send + Sync + 'static>( &self, key: &str, options: CacheGetOptions, ) -> Option<CacheGetResult<T>>
Retrieves a cached result with configurable options
This unified method handles expiration, staleness checking, and other cache retrieval options.
§Arguments
&self- A reference to theProviderCache.key- The key to retrieve.options- Cache retrieval options (expiration, stale time, etc.)
§Returns
An Option<CacheGetResult<T>> containing the cached data and staleness info if available.
§Example
use dioxus_provider::cache::{ProviderCache, CacheGetOptions};
use std::time::Duration;
let cache = ProviderCache::new();
let options = CacheGetOptions::new()
.with_expiration(Duration::from_secs(300))
.with_stale_time(Duration::from_secs(60));
if let Some(result) = cache.get_with_options::<String>("my_key", options) {
println!("Data: {}, Stale: {}", result.data, result.is_stale);
}Sourcepub fn get_with_expiration<T: Clone + Send + Sync + 'static>(
&self,
key: &str,
expiration: Option<Duration>,
) -> Option<T>
👎Deprecated since 0.1.0: Use get_with_options() instead for more flexible cache retrieval
pub fn get_with_expiration<T: Clone + Send + Sync + 'static>( &self, key: &str, expiration: Option<Duration>, ) -> Option<T>
Retrieves a cached result by key, checking for expiration with a specific expiration duration.
§Deprecated
Use get_with_options() instead for more flexible cache retrieval.
§Arguments
&self- A reference to theProviderCache.key- The key to retrieve.expiration- An optional duration after which the entry is considered expired.
§Returns
An Option<T> containing the cached data if available and not expired, or None if expired.
§Side Effects
If expired, the entry is removed from the cache.
Sourcepub fn get_with_staleness<T: Clone + Send + Sync + 'static>(
&self,
key: &str,
stale_time: Option<Duration>,
expiration: Option<Duration>,
) -> Option<(T, bool)>
👎Deprecated since 0.1.0: Use get_with_options() instead for more flexible cache retrieval
pub fn get_with_staleness<T: Clone + Send + Sync + 'static>( &self, key: &str, stale_time: Option<Duration>, expiration: Option<Duration>, ) -> Option<(T, bool)>
Retrieves cached data with staleness information for SWR behavior.
§Deprecated
Use get_with_options() instead for more flexible cache retrieval.
§Arguments
&self- A reference to theProviderCache.key- The key to retrieve.stale_time- An optional duration after which the entry is considered stale.expiration- An optional duration after which the entry is considered expired.
§Returns
An Option<(T, bool)> containing the cached data and a boolean indicating staleness.
§Side Effects
None.
Sourcepub fn set<T: Clone + Send + Sync + PartialEq + 'static>(
&self,
key: String,
value: T,
) -> bool
pub fn set<T: Clone + Send + Sync + PartialEq + 'static>( &self, key: String, value: T, ) -> bool
Sourcepub fn invalidate(&self, key: &str)
pub fn invalidate(&self, key: &str)
Sourcepub fn cleanup_unused_entries(&self, unused_threshold: Duration) -> usize
pub fn cleanup_unused_entries(&self, unused_threshold: Duration) -> usize
Sourcepub fn evict_lru_entries(&self, max_size: usize) -> usize
pub fn evict_lru_entries(&self, max_size: usize) -> usize
Sourcepub fn maintain(&self) -> CacheMaintenanceStats
pub fn maintain(&self) -> CacheMaintenanceStats
Trait Implementations§
Source§impl Clone for ProviderCache
impl Clone for ProviderCache
Source§fn clone(&self) -> ProviderCache
fn clone(&self) -> ProviderCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more