getCurrentWindow method

  1. @override
FutureOr<RateLimitingWindow<User>> getCurrentWindow(
  1. RequestContext req,
  2. ResponseContext res,
  3. DateTime currentTime
)
override

Computes the current window in which the user is acting.

For example, if your API was limited to 1000 requests/hour, then you would return a window containing the current hour, and the number of requests the user has sent in the past hour.

Implementation

@override
FutureOr<RateLimitingWindow<User>> getCurrentWindow(
    RequestContext req, ResponseContext res, DateTime currentTime) async {
  var user = await getUser(req, res);
  return _cache[user] ??= RateLimitingWindow(user, currentTime, 0);
}