Interface RateLimitStore
- All Known Implementing Classes:
InMemoryRateLimitStore
Persistent event store for sliding-window rate-limiting policies
(V00.70 Phase 7c).
The store is intentionally event-based rather than a
counter + window-start pair: a RateLimitStore records one
timestamp per event, and the policy decides how to interpret that
stream — a fixed window, a sliding window, a leaky bucket, or a
token bucket are all expressible on top of the same primitives.
Lifecycle:
recordEvent(RateLimitKey, Instant)appends one timestamp.countSince(RateLimitKey, Instant)returns how many events the key holds at or after the cutoff — the policy pickscutoff = now - window.reset(RateLimitKey)drops everything under a key (typically called on a successful authentication that cancels the throttle).purgeOlderThan(Instant)is the retention sweep — runs on a schedule, drops events the policy would no longer count anyway.
Implementations must be thread-safe; concurrent recordEvent and countSince happen on every protected endpoint.
-
Method Summary
Modifier and TypeMethodDescriptionintcountSince(RateLimitKey key, Instant since) Returns the number of events underkeywhose timestamp is at or aftersince.intpurgeOlderThan(Instant cutoff) Across every key, drops events whose timestamp is strictly beforecutoff.voidrecordEvent(RateLimitKey key, Instant at) Appends one event timestamp underkey.voidreset(RateLimitKey key) Drops every recorded event underkey.
-
Method Details
-
recordEvent
Appends one event timestamp underkey.- Parameters:
key- key the event belongs to; must not benullat- event instant; must not benull
-
countSince
Returns the number of events underkeywhose timestamp is at or aftersince.- Parameters:
key- key to query; must not benullsince- inclusive lower bound; events at exactly this instant count; must not benull- Returns:
- non-negative event count
-
reset
Drops every recorded event underkey.- Parameters:
key- key to clear; must not benull
-
purgeOlderThan
Across every key, drops events whose timestamp is strictly beforecutoff. Intended as a retention sweep.- Parameters:
cutoff- retention boundary; must not benull- Returns:
- number of events purged
-