pub struct LocalCounterStore {
windows: DashMap<String, (Instant, u64)>,
}Expand description
In-memory fixed-window counters (per gateway instance).
Windows are tracked per key as (window_start, count); a request past
the window’s end lazily starts a fresh window. Entries are never actively
expired — stale keys are reset on their next request; memory is bounded
by key cardinality, same as the existing token-bucket plugin.
Fields§
§windows: DashMap<String, (Instant, u64)>Trait Implementations§
Source§impl CounterStore for LocalCounterStore
impl CounterStore for LocalCounterStore
Source§fn incr_fixed_window<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u64,
window: Duration,
) -> Pin<Box<dyn Future<Output = Result<WindowResult, CounterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn incr_fixed_window<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u64,
window: Duration,
) -> Pin<Box<dyn Future<Output = Result<WindowResult, CounterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Atomically counts one request for
key in the current fixed window
of length window, allowing up to limit requests per window.Source§impl Default for LocalCounterStore
impl Default for LocalCounterStore
Source§fn default() -> LocalCounterStore
fn default() -> LocalCounterStore
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for LocalCounterStore
impl !RefUnwindSafe for LocalCounterStore
impl Send for LocalCounterStore
impl Sync for LocalCounterStore
impl Unpin for LocalCounterStore
impl UnsafeUnpin for LocalCounterStore
impl UnwindSafe for LocalCounterStore
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more