pub struct SmartCache<V: CacheValue> { /* private fields */ }Expand description
Size-aware LRU cache with automatic cleanup.
Uses DashMap for lock-free concurrent reads. Writes are per-shard
and do not block readers on other shards.
Implementations§
Source§impl<V: CacheValue> SmartCache<V>
impl<V: CacheValue> SmartCache<V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new cache with default settings.
Default: 1000 entries, 50MB max size, 5 minute TTL.
Sourcepub fn with_limits(
max_entries: usize,
max_size_bytes: usize,
default_ttl: Duration,
) -> Self
pub fn with_limits( max_entries: usize, max_size_bytes: usize, default_ttl: Duration, ) -> Self
Create with custom limits.
Sourcepub async fn set_with_ttl(
&self,
key: impl Into<String>,
value: V,
ttl: Duration,
)
pub async fn set_with_ttl( &self, key: impl Into<String>, value: V, ttl: Duration, )
Set a value with custom TTL.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get current size in bytes.
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
Get cache statistics.
Sourcepub async fn cleanup_expired(&self)
pub async fn cleanup_expired(&self)
Clean up expired entries.
Sourcepub fn start_cleanup_task(self: Arc<Self>, interval: Duration) -> JoinHandle<()>
pub fn start_cleanup_task(self: Arc<Self>, interval: Duration) -> JoinHandle<()>
Start a background cleanup task.
Runs cleanup every interval duration.
Trait Implementations§
Source§impl<V: Debug + CacheValue> Debug for SmartCache<V>
impl<V: Debug + CacheValue> Debug for SmartCache<V>
Source§impl<V: CacheValue> Default for SmartCache<V>
impl<V: CacheValue> Default for SmartCache<V>
Auto Trait Implementations§
impl<V> Freeze for SmartCache<V>
impl<V> !RefUnwindSafe for SmartCache<V>
impl<V> Send for SmartCache<V>
impl<V> Sync for SmartCache<V>
impl<V> Unpin for SmartCache<V>
impl<V> UnsafeUnpin for SmartCache<V>
impl<V> !UnwindSafe for SmartCache<V>
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