Soenneker.Validators.ExpiringKey
2.1.20
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Soenneker.Validators.ExpiringKey --version 2.1.20
NuGet\Install-Package Soenneker.Validators.ExpiringKey -Version 2.1.20
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="2.1.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.Validators.ExpiringKey --version 2.1.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Soenneker.Validators.ExpiringKey, 2.1.20"
#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.
// Install Soenneker.Validators.ExpiringKey as a Cake Addin
#addin nuget:?package=Soenneker.Validators.ExpiringKey&version=2.1.20
// Install Soenneker.Validators.ExpiringKey as a Cake Tool
#tool nuget:?package=Soenneker.Validators.ExpiringKey&version=2.1.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Soenneker.Validators.ExpiringKey
A validation module that checks for keys, stores them, expires them after an amount of time
Ideal for caching, session management, and more.
🚀 Features
- Validate Key: Check if a key exists.
- Add Key: Add a key with an expiration time.
- Validate and Add: Validate if a key exists and add it if not.
- Remove Key: Remove a key.
Installation
dotnet add package Soenneker.Validators.ExpiringKey
💻 Usage
IExpiringKeyValidator
can be registered within DI, and injected:
public static async Task Main(string[] args)
{
...
builder.Services.AddExpiringKeyValidatorAsSingleton();
}
or it can be initialized manually: new ExpiringKeyValidator()
.
Validate Key
Check if a key is present.
bool Validate(string key)
Add Key
Add a key with an expiration time.
void Add(string key, int expirationTimeMilliseconds)
Validate and Add Key
Validate a key and add it if it doesn't exist.
bool ValidateAndAdd(string key, int expirationTimeMilliseconds) // true if doesn't exist, false if it does
Remove Key
Remove a key.
void Remove(string key)
Example
var validator = new ExpiringKeyValidator();
validator.Add("key1", 5000); // 5 seconds
var invalid = validator.Validate("key1"); // false, key exists
await Task.Delay(7000); // wait 7 seconds
var validAfterTime = validator.Validate("key1"); // true, key does not exist
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Soenneker.Dictionaries.ExpiringKey (>= 2.1.20)
- Soenneker.Validators.Validator (>= 2.1.237)
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 |
---|---|---|
2.1.24 | 32 | 6/27/2024 |
2.1.23 | 37 | 6/27/2024 |
2.1.22 | 34 | 6/27/2024 |
2.1.21 | 31 | 6/27/2024 |
2.1.20 | 69 | 6/22/2024 |
2.1.19 | 60 | 6/22/2024 |
2.1.18 | 66 | 6/22/2024 |
2.1.17 | 66 | 6/22/2024 |
2.1.16 | 66 | 6/22/2024 |
2.1.15 | 69 | 6/16/2024 |
2.1.14 | 59 | 6/16/2024 |
2.1.13 | 66 | 6/15/2024 |
2.1.12 | 63 | 6/15/2024 |
2.1.11 | 62 | 6/15/2024 |
2.1.10 | 63 | 6/15/2024 |
2.1.9 | 68 | 6/15/2024 |
2.1.8 | 62 | 6/15/2024 |
2.1.7 | 62 | 6/15/2024 |
2.1.6 | 65 | 6/15/2024 |
2.1.5 | 62 | 6/15/2024 |
2.1.4 | 61 | 6/12/2024 |
2.1.3 | 56 | 6/12/2024 |