allow method

bool allow(
  1. String key,
  2. DateTime now
)

Implementation

bool allow(String key, DateTime now) {
  _windows.removeWhere((_, entry) => !now.isBefore(entry.$1.add(window)));
  final current = _windows[key];
  if (current == null || !now.isBefore(current.$1.add(window))) {
    if (current == null && _windows.length >= maxTrackedKeys) return false;
    _windows[key] = (now, 1);
    return true;
  }
  if (current.$2 >= maxRequests) return false;
  _windows[key] = (current.$1, current.$2 + 1);
  return true;
}