Skip to content

Commit e2be3c3

Browse files
committed
minor #18962 [RateLimiter] Add SlidingWindowLimiter::reserve() (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [RateLimiter] Add `SlidingWindowLimiter::reserve()` Fix #18956 Doctor-RST's complaining but I'm not 100% sure how to adapt in this case, as it is a mix of deprecation and versionadded 🤔 Commits ------- b5b0093 [RateLimiter] Add `SlidingWindowLimiter::reserve()`
2 parents 1f34a67 + b5b0093 commit e2be3c3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

rate_limiter.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ processes by reserving unused tokens.
320320
$limit->wait();
321321
} while (!$limit->isAccepted());
322322

323+
.. versionadded:: 6.4
324+
325+
The support for the ``reserve()`` method for the ``SlidingWindow`` strategy
326+
was introduced in Symfony 6.4.
327+
323328
Exposing the Rate Limiter Status
324329
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
325330

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

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

373+
.. versionadded:: 6.4
374+
375+
The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens`
376+
method was introduced in Symfony 6.4.
377+
378+
.. deprecated:: 6.4
379+
380+
The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::getRetryAfter`
381+
method is deprecated since Symfony 6.4. Prior to this version, the
382+
``getRetryAfter()`` method must be used instead of the
383+
:method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens`
384+
method.
385+
368386
.. _rate-limiter-storage:
369387

370388
Storing Rate Limiter State

0 commit comments

Comments
 (0)