Soenneker.Sets.Concurrent.SlidingWindow 4.0.67

Prefix Reserved
There is a newer version of this package available.
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
                    
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="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.67" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.67" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Sets.Concurrent.SlidingWindow" />
                    
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 Soenneker.Sets.Concurrent.SlidingWindow --version 4.0.67
                    
#r "nuget: Soenneker.Sets.Concurrent.SlidingWindow, 4.0.67"
                    
#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 Soenneker.Sets.Concurrent.SlidingWindow@4.0.67
                    
#: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=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.67
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.67
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 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.

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
Loading failed

Protect refreshed sliding window entries