![]() |
VOOZH | about |
dotnet add package Soenneker.Sets.Concurrent.SlidingWindow --version 4.0.46
NuGet\Install-Package Soenneker.Sets.Concurrent.SlidingWindow -Version 4.0.46
<PackageReference Include="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.46" />
<PackageVersion Include="Soenneker.Sets.Concurrent.SlidingWindow" Version="4.0.46" />Directory.Packages.props
<PackageReference Include="Soenneker.Sets.Concurrent.SlidingWindow" />Project file
paket add Soenneker.Sets.Concurrent.SlidingWindow --version 4.0.46
#r "nuget: Soenneker.Sets.Concurrent.SlidingWindow, 4.0.46"
#:package Soenneker.Sets.Concurrent.SlidingWindow@4.0.46
#addin nuget:?package=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.46Install as a Cake Addin
#tool nuget:?package=Soenneker.Sets.Concurrent.SlidingWindow&version=4.0.46Install 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 provides a concurrent sliding-window set for .NET.
Items added to the set automatically expire after a configurable time window without requiring manual cleanup.
The implementation is optimized for high-concurrency workloads and avoids expensive per-item timers by using a bucketed time-slice rotation system.
This makes it ideal for deduplication, rate limiting, and recent activity tracking.
dotnet add package Soenneker.Sets.Concurrent.SlidingWindow
Many systems need to track items that should only exist for a limited period of time, such as:
Traditional options have downsides:
| Approach | Problem |
|---|---|
ConcurrentDictionary |
Requires manual expiration |
MemoryCache |
Heavy and feature-rich for simple tracking |
| Per-item timers | Extremely expensive at scale |
| Background cleanup scans | High CPU cost |
SlidingWindowConcurrentSet solves this by using bucketed time slices where items automatically expire when their time window passes.
✔ High-throughput concurrent operations
✔ Automatic expiration of entries
✔ Sliding window time-based retention
✔ Lock-minimized design
✔ Low allocation footprint
✔ No per-item timers
✔ Safe for heavy multi-threaded workloads
using Soenneker.Sets.Concurrent.SlidingWindow;
var set = new SlidingWindowConcurrentSet<string>(
window: TimeSpan.FromMinutes(5),
rotationInterval: TimeSpan.FromSeconds(30)
);
set.TryAdd("alpha");
bool exists = set.Contains("alpha");
await Task.Delay(TimeSpan.FromMinutes(6));
bool expired = set.Contains("alpha"); // false
var set = new SlidingWindowConcurrentSet<string>(
window: TimeSpan.FromMinutes(10),
rotationInterval: TimeSpan.FromSeconds(15)
);
| Parameter | Description |
|---|---|
window |
Total time items remain valid |
rotationInterval |
Time slice size used for bucket rotation |
capacityHint |
Initial capacity hint for the internal dictionary |
comparer |
Optional equality comparer |
The window is internally divided into time buckets:
window / rotationInterval = number of buckets
Example:
window = 5 minutes
rotationInterval = 30 seconds
bucket count = 10
Each rotation advances the window and expires the oldest bucket.
The set maintains:
When an item is added:
A background rotation process periodically:
This avoids scanning the entire collection.
| Operation | Complexity |
|---|---|
TryAdd |
O(1) |
Contains |
O(1) |
TryRemove |
O(1) |
| Expiration | O(n) only for items in expiring bucket |
The design ensures:
All operations are thread-safe.
The set is designed for high-concurrency environments and does not require external synchronization.
The set uses an internal rotation task driven by PeriodicTimer.
When the set is no longer needed, it should be disposed:
set.Dispose();
or
await set.DisposeAsync();
This stops the internal rotation loop.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
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. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.46 | 0 | 6/19/2026 |
| 4.0.45 | 0 | 6/19/2026 |
| 4.0.44 | 5 | 6/18/2026 |
| 4.0.43 | 398 | 6/6/2026 |
| 4.0.42 | 154 | 6/6/2026 |
| 4.0.41 | 93 | 6/6/2026 |
| 4.0.40 | 95 | 6/5/2026 |
| 4.0.39 | 96 | 6/5/2026 |
| 4.0.37 | 851 | 4/23/2026 |
| 4.0.35 | 137 | 4/22/2026 |
| 4.0.34 | 102 | 4/22/2026 |
| 4.0.33 | 109 | 4/22/2026 |
| 4.0.32 | 494 | 3/13/2026 |
| 4.0.31 | 110 | 3/13/2026 |
| 4.0.30 | 108 | 3/13/2026 |
| 4.0.29 | 144 | 3/13/2026 |
| 4.0.28 | 112 | 3/12/2026 |
| 4.0.27 | 102 | 3/12/2026 |
| 4.0.26 | 109 | 3/12/2026 |
| 4.0.24 | 111 | 3/12/2026 |
Update dependency Soenneker.Extensions.Task to 4.0.123 (#111)