Soenneker.Validators.ExpiringKey 11.0.1376

Prefix Reserved
dotnet add package Soenneker.Validators.ExpiringKey --version 11.0.1376
                    
NuGet\Install-Package Soenneker.Validators.ExpiringKey -Version 11.0.1376
                    
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.Validators.ExpiringKey" Version="11.0.1376" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Validators.ExpiringKey" Version="11.0.1376" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Validators.ExpiringKey" />
                    
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.Validators.ExpiringKey --version 11.0.1376
                    
#r "nuget: Soenneker.Validators.ExpiringKey, 11.0.1376"
                    
#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.Validators.ExpiringKey@11.0.1376
                    
#: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.Validators.ExpiringKey&version=11.0.1376
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Validators.ExpiringKey&version=11.0.1376
                    
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

alternate text is missing from this package README image Soenneker.Validators.ExpiringKey

An in-memory, thread-safe expiring-key gate for suppressing duplicate work within a time window.

Installation

dotnet add package Soenneker.Validators.ExpiringKey

Registration

using Soenneker.Validators.ExpiringKey.Registrars;

services.AddExpiringKeyValidatorAsSingleton();

Singleton registration shares keys across all callers in the process. Scoped registration creates an independent key set per dependency-injection scope. The validator requires an ILogger<ExpiringKeyValidator> when constructed manually.

Atomic check-and-add

bool accepted = validator.ValidateAndAdd(
    key: $"webhook:{eventId}",
    expirationTimeMilliseconds: 30_000);

if (!accepted)
    return; // The key already exists in the current window.

ValidateAndAdd is the safest operation for duplicate suppression because the existence check and insertion are atomic. It returns true only to the caller that added the key. The key is removed by its timer after the supplied interval.

Individual operations

validator.Add("job:42", 5_000);

bool available = validator.Validate("job:42");
// false: the key exists

validator.Remove("job:42");

available = validator.Validate("job:42");
// true: the key is absent

Validate has intentionally inverted gate semantics: it returns true when the key does not exist and false while the key is present. It does not reserve an absent key, so a separate Validate followed by Add is racy under concurrency; use ValidateAndAdd when only one caller may proceed.

Add attempts insertion and returns no result. If the key already exists, its original expiration is retained; the call does not refresh or replace its timer. Remove is idempotent and synchronously disposes the removed timer.

Expiration and lifetime

Expiration is an in-process timer duration in milliseconds. Values below -1 throw ArgumentOutOfRangeException; -1 represents an infinite timeout. Expiration callbacks run asynchronously, so a zero-duration key may be observable briefly before its callback removes it.

This is not a distributed lock, durable cache, session store, or cross-process idempotency mechanism. Process restarts lose all keys, and separate validator instances do not share state.

The validator owns one timer per live key. Dispose it to release all timers; dependency injection handles disposal for registered instances. Calls after disposal follow the underlying dictionary's disposed-object behavior.

Keys use the underlying concurrent dictionary's default string comparison. Avoid placing secrets or unbounded attacker-controlled values into a long-lived singleton without applying size and cardinality limits at the caller.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.1376 54 12/2/2026
11.0.1375 96 12/1/2026
11.0.1374 100 11/30/2026
11.0.1373 107 11/18/2026
11.0.1372 107 11/18/2026
11.0.1370 130 11/11/2026
11.0.1369 102 11/11/2026
11.0.1367 244 10/27/2026
11.0.1366 113 10/27/2026
11.0.1365 111 10/26/2026
11.0.1364 101 10/26/2026
11.0.1363 114 10/26/2026
11.0.1362 108 10/26/2026
11.0.1361 111 10/26/2026
4.0.1360 110 10/25/2026
4.0.1359 141 10/14/2026
4.0.1358 127 10/14/2026
4.0.1357 113 10/14/2026
4.0.1356 120 10/14/2026
4.0.1355 110 10/14/2026
Loading failed

Updated Multiple NuGet packages