Vrmac.RateLimits
1.0.0
dotnet add package Vrmac.RateLimits --version 1.0.0
NuGet\Install-Package Vrmac.RateLimits -Version 1.0.0
<PackageReference Include="Vrmac.RateLimits" Version="1.0.0" />
<PackageVersion Include="Vrmac.RateLimits" Version="1.0.0" />
<PackageReference Include="Vrmac.RateLimits" />
paket add Vrmac.RateLimits --version 1.0.0
#r "nuget: Vrmac.RateLimits, 1.0.0"
#:package Vrmac.RateLimits@1.0.0
#addin nuget:?package=Vrmac.RateLimits&version=1.0.0
#tool nuget:?package=Vrmac.RateLimits&version=1.0.0
Vrmac.RateLimits
This project builds a .NET 10 library to implement rate limits for network requests.
Specifically, the library implements two public classes.
AnonRateLimiterimplements a rate limiter which throttles requests per IP (IPv4) or subnet (IPv6).UserRateLimiterimplements a rate limiter which throttles requests based on uint64 keys.
The implementation is quite similar. The only difference is the key used in the hash maps.
The rateLimit public methods are thread safe and reentrant.
Note both classes should be singletons.
They have internal mutable state to track time, and you only need a single instance of each.
The constructor of both classes takes a cancellation token.
If you are consuming this library from an asp.net web app, I recommend passing the following token:
static AnonRateLimiter? anonRateLimiter = null;
static UserRateLimiter? userRateLimiter = null;
static void applicationStartup( WebApplication app )
{
IHostApplicationLifetime lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
CancellationToken appStopping = lifetime.ApplicationStopping;
// Construct both rate limiters: anonymous 1Hz per IP4 address or IP6 subnet, and 4Hz for users
anonRateLimiter = new( appStopping );
userRateLimiter = new( appStopping );
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 84 | 9/30/2026 |