Vrmac.RateLimits 1.0.0

dotnet add package Vrmac.RateLimits --version 1.0.0
                    
NuGet\Install-Package Vrmac.RateLimits -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Vrmac.RateLimits" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vrmac.RateLimits" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Vrmac.RateLimits" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Vrmac.RateLimits --version 1.0.0
                    
#r "nuget: Vrmac.RateLimits, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Vrmac.RateLimits@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Vrmac.RateLimits&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Vrmac.RateLimits&version=1.0.0
                    
Install as a Cake Tool

Vrmac.RateLimits

This project builds a .NET 10 library to implement rate limits for network requests.
Specifically, the library implements two public classes.

  1. AnonRateLimiter implements a rate limiter which throttles requests per IP (IPv4) or subnet (IPv6).

  2. UserRateLimiter implements 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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