pub struct MemoryStorage { /* private fields */ }Expand description
In-memory storage with garbage collection.
Uses DashMap for thread-safe concurrent access and includes
configurable garbage collection to prevent unbounded memory growth.
§Example
ⓘ
use skp_ratelimit::storage::{MemoryStorage, GcConfig};
use std::time::Duration;
// Default GC (every 10000 requests)
let storage = MemoryStorage::new();
// Custom GC interval
let storage = MemoryStorage::with_gc(GcConfig::on_duration(Duration::from_secs(60)));
// Manual GC only
let storage = MemoryStorage::with_gc(GcConfig::manual());
storage.run_gc().await;Implementations§
Trait Implementations§
Source§impl Debug for MemoryStorage
impl Debug for MemoryStorage
Source§impl Default for MemoryStorage
impl Default for MemoryStorage
Source§impl Drop for MemoryStorage
impl Drop for MemoryStorage
Source§impl Storage for MemoryStorage
impl Storage for MemoryStorage
Source§async fn set(&self, key: &str, entry: StorageEntry, ttl: Duration) -> Result<()>
async fn set(&self, key: &str, entry: StorageEntry, ttl: Duration) -> Result<()>
Set an entry with a TTL. Read more
Source§async fn increment(
&self,
key: &str,
delta: u64,
window_start: u64,
ttl: Duration,
) -> Result<u64>
async fn increment( &self, key: &str, delta: u64, window_start: u64, ttl: Duration, ) -> Result<u64>
Atomically increment a counter. Read more
Source§async fn execute_atomic<F, T>(
&self,
key: &str,
ttl: Duration,
operation: F,
) -> Result<T>
async fn execute_atomic<F, T>( &self, key: &str, ttl: Duration, operation: F, ) -> Result<T>
Execute an atomic read-modify-write operation. Read more
Source§async fn compare_and_swap(
&self,
key: &str,
expected: Option<&StorageEntry>,
new: StorageEntry,
ttl: Duration,
) -> Result<bool>
async fn compare_and_swap( &self, key: &str, expected: Option<&StorageEntry>, new: StorageEntry, ttl: Duration, ) -> Result<bool>
Compare-and-swap operation. Read more
Auto Trait Implementations§
impl !Freeze for MemoryStorage
impl !RefUnwindSafe for MemoryStorage
impl Send for MemoryStorage
impl Sync for MemoryStorage
impl Unpin for MemoryStorage
impl UnwindSafe for MemoryStorage
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