NCache.OSS.RateLimiting
5.3.603
dotnet add package NCache.OSS.RateLimiting --version 5.3.603
NuGet\Install-Package NCache.OSS.RateLimiting -Version 5.3.603
<PackageReference Include="NCache.OSS.RateLimiting" Version="5.3.603" />
<PackageVersion Include="NCache.OSS.RateLimiting" Version="5.3.603" />
<PackageReference Include="NCache.OSS.RateLimiting" />
paket add NCache.OSS.RateLimiting --version 5.3.603
#r "nuget: NCache.OSS.RateLimiting, 5.3.603"
#:package NCache.OSS.RateLimiting@5.3.603
#addin nuget:?package=NCache.OSS.RateLimiting&version=5.3.603
#tool nuget:?package=NCache.OSS.RateLimiting&version=5.3.603
NCache RateLimiting Integration
NCache integration for the .NET rate limiting API. This package provides concurrency, fixed window, sliding window and token bucket limiters whose state lives in an NCache cluster, so a limit is enforced across all application instances rather than per process. It plugs into System.Threading.RateLimiting (RateLimiter, RateLimitPartition, PartitionedRateLimiter) and the ASP.NET Core Microsoft.AspNetCore.RateLimiting middleware.
Installation
Install-Package NCache.OSS.RateLimiting
or, using the .NET CLI:
dotnet add package NCache.OSS.RateLimiting
What is Installed
Installing this package adds the following NCache configuration files to your project:
- client.ncconf — Defines the cache client settings, including the cache name and the list of server nodes the client connects to.
- config.ncconf — Contains the cache configuration (cache topology, partitions, eviction policy, etc.) used when the cache is created/registered.
Prerequisites
- .NET 8.0 or higher.
- An NCache 5.3.603 (or later) server should be up and running, with the target cache already created/registered on it.
Getting Started
Setting up NCache
The servers can be given in code (shown below). If you leave ServerList empty, the client reads them from a client.ncconf in your project; in that case, if NCache is not installed on the current machine, add one and set the cache id to your cache name:
<configuration>
<ncache-server port="9800" />
<cache id="defaultCache" enable-client-logs="False" log-level="error">
<server name="10.0.0.1" />
</cache>
</configuration>
Change defaultCache to the name of your actual cache, and 10.0.0.1 to the IP/hostname of a node hosting it. Mark the file to be copied to the output directory.
Setting up Package
Register the limiters as named policies of the ASP.NET Core rate limiter, then apply a policy to the endpoints you want to protect:
using Microsoft.AspNetCore.RateLimiting;
using NCache.OSS.RateLimiting;
builder.Services.AddRateLimiter(options =>
{
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
options.AddNCacheFixedWindowLimiter("orders", limiter =>
{
limiter.PermitLimit = 100;
limiter.Window = TimeSpan.FromMinutes(1);
limiter.CacheName = "defaultCache";
limiter.ServerList.Add(new NCache.OSS.RateLimiting.RateLimiterOptions.ServerConfig { Ip = "10.0.0.1", Port = 9800 });
});
});
var app = builder.Build();
app.UseRateLimiter();
app.MapPost("/order", () => Results.Ok()).RequireRateLimiting("orders");
Because the counters are kept in NCache, every instance behind the load balancer draws from the same 100 permits per minute.
The same limiters are available as plain RateLimiter instances and as partitions (for example one limit per user or per IP):
var limiter = new FixedWindowRateLimiter<string>("orders", new FixedWindowLimiterOptions
{
PermitLimit = 100,
Window = TimeSpan.FromMinutes(1),
CacheName = "defaultCache"
});
PartitionedRateLimiter<HttpContext> partitioned = PartitionedRateLimiter.Create<HttpContext, string>(context =>
NCache.OSS.RateLimiting.RateLimitPartition.GetFixedWindowRateLimiter(
context.User.Identity?.Name ?? "anonymous",
key => new FixedWindowLimiterOptions
{
PermitLimit = 20,
Window = TimeSpan.FromMinutes(1),
CacheName = "defaultCache"
}));
Configuration
Every limiter's options derive from RateLimiterOptions, which carries the connection settings.
| Property | Description |
|---|---|
CacheName |
Name of the NCache cache that holds the limiter state. Required. |
ServerList |
NCache server nodes to connect to (Ip, and Port which defaults to 9800). If empty, client.ncconf is used. |
Port |
Default NCache client port (9800). |
Each limiter adds its own settings:
| Limiter | Registration | Options |
|---|---|---|
| Concurrency | AddNCacheConcurrencyLimiter |
PermitLimit, QueueLimit, TryDequeuePeriod (1 s), ExpectedRequestTimeout (60 s), LockTimeout (10 s) |
| Fixed window | AddNCacheFixedWindowLimiter |
PermitLimit, Window, LockTimeout (5 s) |
| Sliding window | AddNCacheSlidingWindowLimiter |
PermitLimit, Window, LockTimeout (5 s) |
| Token bucket | AddNCacheTokenBucketLimiter |
TokenLimit, TokensPerPeriod, ReplenishmentPeriod, LockTimeout (5 s) |
The package provides:
- Concurrency limiter — bounds the number of in-flight requests; excess requests wait in a first-in-first-out queue shared by all nodes and are rejected once
QueueLimitis reached. - Fixed window limiter — allows up to
PermitLimitrequests per window, resetting the count when the window elapses. - Sliding window limiter — tracks individual request timestamps and slides the window continuously, avoiding the burst at a fixed window's boundary.
- Token bucket limiter — refills tokens at a steady rate, allowing short bursts up to
TokenLimitwhile enforcing a long-run average. AddNCache...Limiterextension methods for the ASP.NET Core middleware, andRateLimitPartition.Get...RateLimiterhelpers for partitioned limiters.
State keys expire in NCache on their own, so a process that crashes while holding a lease does not block the limit forever.
Resources
Technical Support
Alachisoft provides various technical support resources.
Visit the Alachisoft Support Center to select a support resource appropriate for your issue.
To request additional features or report a documentation discrepancy, contact support@alachisoft.com.
License
Copyright © 2026 Alachisoft. All rights reserved.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net7.0
- Alachisoft.NCache.Opensource.SDK (>= 5.3.603)
- System.Threading.RateLimiting (>= 10.0.12)
-
net8.0
- Alachisoft.NCache.Opensource.SDK (>= 5.3.603)
- System.Threading.RateLimiting (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.