Soenneker.Sets.Concurrent.SlidingWindow
4.0.67
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Sets.Concurrent.SlidingWindow --version 4.0.67
NuGet\Install-Package Soenneker.Sets.Concurrent.SlidingWindow -Version 4.0.67
<PackageReference Include="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.67" />
<PackageVersion Include="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.67" />
<PackageReference Include="Soenneker.Sets.Concurrent.SlidingWindow" />
paket add Soenneker.Sets.Concurrent.SlidingWindow --version 4.0.67
#r "nuget: Soenneker.Sets.Concurrent.SlidingWindow, 4.0.67"
#:package Soenneker.Sets.Concurrent.SlidingWindow@4.0.67
#addin nuget:?package=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.67
#tool nuget:?package=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.67
Soenneker.Sets.Concurrent.SlidingWindow
A concurrent set that refreshes values into time buckets and expires them with one internal periodic rotation task.
Installation
dotnet add package Soenneker.Sets.Concurrent.SlidingWindow
Usage
using Soenneker.Sets.Concurrent.SlidingWindow;
await using var recentIds = new SlidingWindowConcurrentSet<string>(
window: TimeSpan.FromMinutes(5),
rotationInterval: TimeSpan.FromSeconds(30),
capacityHint: 10_000,
comparer: StringComparer.Ordinal);
if (!recentIds.TryAdd(messageId))
{
// The ID was already present. This call may also refresh its bucket.
return;
}
bool isRecent = recentIds.Contains(messageId);
bool removed = recentIds.TryRemove(messageId);
string[] snapshot = recentIds.ToArray();
TryAdd returns true only when the value was absent from the dictionary. If the value is already present from an earlier bucket, it returns false and refreshes that value into the current bucket. Repeated add attempts can therefore extend retention even though they report a duplicate. A duplicate within the same bucket returns false without adding another bucket record.
Expiration precision
The constructor creates max(2, ceil(window / rotationInterval)) buckets. Entries expire when their last bucket rotates out, so expiration is quantized rather than exact.
With a five-minute window and a 30-second rotation interval, an unrefreshed entry normally remains for roughly 4.5 to 5 minutes depending on where within the current slice it was added. Timer scheduling delays can extend that further. When rotationInterval is greater than or equal to window, the two-bucket minimum means retention is roughly one to two rotation intervals.
Choose an interval small enough for the expiration precision your use case needs, while remembering that every interval runs a bucket cleanup pass.
Collection views
Contains checks both the dictionary and the recorded bucket age. Count, Values, and ToArray read the underlying concurrent dictionary. At a rotation boundary—or if the timer pump is delayed—they can briefly include an entry that Contains already considers expired.
Values is a live concurrent view and may change during enumeration. ToArray allocates a snapshot of keys observed during that call. None of these operations provides a transaction with concurrent adds, refreshes, removals, or expiration.
capacityHint controls only the dictionary's initial capacity. It does not bound the number of live values or queued bucket records. Frequently refreshing values creates stale bucket records that remain until their buckets rotate.
Disposal
Each set owns a PeriodicTimer, cancellation source, and rotation task. Prefer asynchronous disposal when practical because it cancels and awaits the pump:
await recentIds.DisposeAsync();
Dispose and DisposeAsync are idempotent. After disposal, TryAdd, Contains, and TryRemove throw ObjectDisposedException.
This collection is suitable for approximate recent-value tracking and deduplication hints. It is not a durable idempotency store, exact rate limiter, security token revocation list, or TTL cache with per-entry expiration guarantees.
| 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
- Soenneker.Atomics.Longs (>= 4.0.23)
- Soenneker.Atomics.ValueBools (>= 4.0.38)
- Soenneker.Extensions.Task (>= 4.0.128)
- Soenneker.Extensions.ValueTask (>= 4.0.118)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Sets.Concurrent.SlidingWindow:
| Package | Downloads |
|---|---|
|
Soenneker.Deduplication.SlidingWindow
High-performance sliding-window deduplication for .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.68 | 180 | 8/31/2026 |
| 4.0.67 | 83 | 8/30/2026 |
| 4.0.66 | 80 | 8/30/2026 |
| 4.0.65 | 142 | 8/30/2026 |
| 4.0.64 | 82 | 8/30/2026 |
| 4.0.63 | 80 | 8/30/2026 |
| 4.0.62 | 81 | 8/29/2026 |
| 4.0.61 | 666 | 8/8/2026 |
| 4.0.60 | 243 | 7/29/2026 |
| 4.0.59 | 176 | 7/28/2026 |
| 4.0.58 | 106 | 7/28/2026 |
| 4.0.57 | 104 | 7/28/2026 |
| 4.0.56 | 104 | 7/27/2026 |
| 4.0.55 | 339 | 7/18/2026 |
| 4.0.54 | 214 | 7/17/2026 |
| 4.0.53 | 100 | 7/16/2026 |
| 4.0.52 | 144 | 7/16/2026 |
| 4.0.50 | 95 | 7/16/2026 |
| 4.0.49 | 691 | 6/19/2026 |
| 4.0.48 | 169 | 6/19/2026 |
Protect refreshed sliding window entries