8000 [RateLimiter] Add `SlidingWindowLimiter::reserve()` by alexandre-daubois · Pull Request #18962 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[RateLimiter] Add SlidingWindowLimiter::reserve() #18962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[RateLimiter] Add SlidingWindowLimiter::reserve()
  • Loading branch information
alexandre-daubois committed Oct 2, 2023
commit b5b00937f16fa95e9abc58d643a55696789a286d
20 changes: 19 additions & 1 deletion rate_limiter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ processes by reserving unused tokens.
$limit->wait();
} while (!$limit->isAccepted());

.. versionadded:: 6.4

The support for the ``reserve()`` method for the ``SlidingWindow`` strategy
was introduced in Symfony 6.4.

Exposing the Rate Limiter Status
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -348,7 +353,7 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the
$limit = $limiter->consume();
$headers = [
'X-RateLimit-Remaining' => $limit->getRemainingTokens(),
'X-RateLimit-Retry-After' => $limit->getRetryAfter()->getTimestamp(),
'X-RateLimit-Retry-After' => $limit->calculateTimeForTokens(1, 1),
'X-RateLimit-Limit' => $limit->getLimit(),
];

Expand All @@ -365,6 +370,19 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the
}
}

.. versionadded:: 6.4

The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens`
method was introduced in Symfony 6.4.

.. deprecated:: 6.4

The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::getRetryAfter`
method is deprecated since Symfony 6.4. Prior to this version, the
``getRetryAfter()`` method must be used instead of the
:method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens`
method.

.. _rate-limiter-storage:

Storing Rate Limiter State
Expand Down
0