mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 12:34:17 +02:00
docs: clarify LRU eviction safety in rate limiter docstrings
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
12d882cca7
commit
d280a50bfd
1 changed files with 14 additions and 2 deletions
|
|
@ -145,7 +145,13 @@ class RateLimitingMiddleware(Middleware):
|
|||
)
|
||||
|
||||
def _get_limiter(self, client_id: str) -> TokenBucketRateLimiter:
|
||||
"""Get or create a rate limiter for a client, with LRU eviction."""
|
||||
"""Get or create a rate limiter for a client, with LRU eviction.
|
||||
|
||||
When the cache is full, the least-recently-used client is evicted.
|
||||
This is safe because an evicted client was inactive long enough for
|
||||
max_clients other clients to be more recent — by which point their
|
||||
token bucket would have refilled to capacity anyway.
|
||||
"""
|
||||
if client_id in self._client_limiters:
|
||||
self._client_limiters.move_to_end(client_id)
|
||||
return self._client_limiters[client_id]
|
||||
|
|
@ -229,7 +235,13 @@ class SlidingWindowRateLimitingMiddleware(Middleware):
|
|||
)
|
||||
|
||||
def _get_limiter(self, client_id: str) -> SlidingWindowRateLimiter:
|
||||
"""Get or create a rate limiter for a client, with LRU eviction."""
|
||||
"""Get or create a rate limiter for a client, with LRU eviction.
|
||||
|
||||
When the cache is full, the least-recently-used client is evicted.
|
||||
This is safe because an evicted client was inactive long enough for
|
||||
max_clients other clients to be more recent — by which point their
|
||||
sliding window would have expired anyway.
|
||||
"""
|
||||
if client_id in self._client_limiters:
|
||||
self._client_limiters.move_to_end(client_id)
|
||||
return self._client_limiters[client_id]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue