Soenneker.Sets.Concurrent.Bounded 4.0.44

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Sets.Concurrent.Bounded --version 4.0.44
                    
NuGet\Install-Package Soenneker.Sets.Concurrent.Bounded -Version 4.0.44
                    
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.Bounded" Version="4.0.44" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Sets.Concurrent.Bounded" Version="4.0.44" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Sets.Concurrent.Bounded" />
                    
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.Bounded --version 4.0.44
                    
#r "nuget: Soenneker.Sets.Concurrent.Bounded, 4.0.44"
                    
#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.Bounded@4.0.44
                    
#: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.Bounded&version=4.0.44
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Sets.Concurrent.Bounded&version=4.0.44
                    
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.Bounded

A concurrent set with bounded-work, best-effort FIFO eviction after its configured size threshold is exceeded.

Installation

dotnet add package Soenneker.Sets.Concurrent.Bounded

Usage

using Soenneker.Sets.Concurrent.Bounded;

var seenRequestIds = new BoundedConcurrentSet<string>(
    maxSize: 10_000,
    comparer: StringComparer.Ordinal);

if (!seenRequestIds.TryAdd(requestId))
{
    // The value was already present at the time of the add attempt.
    return;
}

bool isPresent = seenRequestIds.Contains(requestId);
bool removed = seenRequestIds.TryRemove(requestId);
string[] snapshot = seenRequestIds.ToArray();

TryAdd returns false for an existing value. A successful addition can still be evicted later by another add. Contains, TryRemove, and enumeration are thread-safe, but a result is only a point-in-time observation while other threads mutate the set.

Bounding and eviction

This is not a strict-capacity collection. With the default five-percent overage, trimming begins only after the approximate count exceeds maxSize + ceil(maxSize * 0.05). Concurrent additions and the per-call work budget can produce a larger temporary overage.

Trimming examines insertion records in approximate FIFO order and removes generation-matched live entries until the count reaches maxSize or the work budget is exhausted. Reading an entry does not refresh it, so this is not LRU behavior.

Removed and re-added values use new generation tokens. Stale queue records cannot remove the newer generation.

ApproxCount is maintained with atomic updates and occasionally resynchronized from the dictionary. Use it for telemetry and heuristics, not for check-then-act correctness. Values is a live concurrent view; ToArray creates a snapshot of keys observed during that call.

Tuning

var set = new BoundedConcurrentSet<string>(
    maxSize: 10_000,
    capacityHint: 10_000,
    trimBatchSize: 64,
    trimStartOveragePercent: 5,
    maxTrimWorkPerCall: 4_096,
    resyncAfterNoProgress: 8,
    queueOverageFactor: 4,
    comparer: StringComparer.Ordinal);
  • capacityHint sets the dictionary's initial capacity; it is not another size limit.
  • trimBatchSize is the minimum eviction work budget when trimming begins.
  • trimStartOveragePercent controls how far above maxSize the approximate count may grow before an add triggers trimming. Use 0 to start immediately above maxSize.
  • maxTrimWorkPerCall caps eviction work performed by one operation.
  • resyncAfterNoProgress controls how many no-removal trim attempts occur before the approximate count is corrected from the dictionary. Use 0 to disable that correction trigger.
  • queueOverageFactor starts bounded stale-record cleanup when the insertion queue estimate exceeds maxSize * factor.
  • comparer controls value equality in the underlying concurrent dictionary.

Use this set when temporary overage and best-effort eviction are acceptable, such as telemetry suppression or bounded deduplication hints. Do not use it as an authorization boundary, durable idempotency store, exact rate limiter, or any other control where eviction timing and strict capacity are correctness requirements.

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

Package Downloads
Soenneker.Deduplication.Bounded

A thread-safe high-performance bounded size deduplication utility for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.46 39 9/24/2026
4.0.45 31 9/24/2026
4.0.44 217 9/15/2026
4.0.43 92 9/15/2026
4.0.42 285 9/12/2026
4.0.41 124 9/12/2026
4.0.38 557 8/30/2026
4.0.37 103 8/30/2026
4.0.36 149 8/30/2026
4.0.35 101 8/29/2026
4.0.34 713 7/28/2026
4.0.33 104 7/28/2026
4.0.32 114 7/27/2026
4.0.31 377 7/17/2026
4.0.30 170 7/16/2026
4.0.29 161 7/16/2026
4.0.28 474 6/19/2026
4.0.27 119 6/19/2026
4.0.26 120 6/19/2026
4.0.25 494 6/6/2026
Loading failed