DevelopmentHelpers.AzureDistributedCache
10.0.0
dotnet add package DevelopmentHelpers.AzureDistributedCache --version 10.0.0
NuGet\Install-Package DevelopmentHelpers.AzureDistributedCache -Version 10.0.0
<PackageReference Include="DevelopmentHelpers.AzureDistributedCache" Version="10.0.0" />
<PackageVersion Include="DevelopmentHelpers.AzureDistributedCache" Version="10.0.0" />
<PackageReference Include="DevelopmentHelpers.AzureDistributedCache" />
paket add DevelopmentHelpers.AzureDistributedCache --version 10.0.0
#r "nuget: DevelopmentHelpers.AzureDistributedCache, 10.0.0"
#:package DevelopmentHelpers.AzureDistributedCache@10.0.0
#addin nuget:?package=DevelopmentHelpers.AzureDistributedCache&version=10.0.0
#tool nuget:?package=DevelopmentHelpers.AzureDistributedCache&version=10.0.0
DevelopmentHelpers.AzureDistributedCache
Overview
**DevelopmentHelpers.AzureDistributedCache is a library that simplifies access to Azure Redis Cache in .NET applications.
Installation
- Add Configuration Settings to your
appsettings.jsonfile:{ "DevelopmentHelpers" : { "AzureDistributedCacheConfiguration": { "DnsName": "--DNS--NAME", "ConnectionString": "-- Connection String --- " } } } - Add the Development Helper Service
builder.Services.AddAzureRedisCache(builder.Configuration);
Code Example
public class IndexModel : PageModel
{
private readonly IDistributedCache cache;
private const string cacheItem = "CacheTime";
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger, IDistributedCache cache)
{
this.cache = cache;
_logger = logger;
}
public async Task OnGetAsync()
{
string value = await cache.GetStringAsync(cacheItem);
if (value == null)
{
value = DateTime.Now.ToString();
var options = new DistributedCacheEntryOptions();
options.SetSlidingExpiration(TimeSpan.FromMinutes(10));
await this.cache.SetStringAsync(cacheItem, value, options);
}
ViewData[cacheItem] = value;
ViewData["CurrentTime"] = DateTime.Now.ToString();
}
}
Motivation
I needed a consistent and easy to use library in .net application.
API Reference (common IDistributedCache methods)
The library exposes/uses the platform IDistributedCache. Common methods:
Task<string?> GetStringAsync(string key, CancellationToken token = default)Task SetStringAsync(string key, string value, DistributedCacheEntryOptions options, CancellationToken token = default)Task RemoveAsync(string key, CancellationToken token = default)Task<byte[]?> GetAsync(string key, CancellationToken token = default)Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = default)Task RefreshAsync(string key, CancellationToken token = default)
Synchronous counterparts also exist on IDistributedCache (e.g., GetString, SetString, Get, Set, Remove), but prefer the async APIs.
Tests
Unit/integration tests in this project assume a configured IDistributedCache is available via your test DI setup. Run tests from the solution directory with:
- dotnet test
Example tests included in this repo show usage patterns for string and byte[] caching and removal.
Troubleshooting
- Ensure your Redis instance allows connections from your host (network rules/firewall).
- Use the correct TLS/SSL settings in your connection string if required by your Redis SKU.
- Check logs for connection or serialization errors.
Contributing & Standards
This project targets .NET 10 and follows the repository's contribution and formatting standards. See CONTRIBUTING.md and .editorconfig for coding style, naming conventions, and test requirements. Keep secrets out of source control — use environment variables or Azure Key Vault for connection strings in CI/CD.
License
Refer to the repository root for license information.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- StackExchange.Redis (>= 2.10.1)
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 |
|---|---|---|
| 10.0.0 | 194 | 12/3/2025 |
| 9.0.3 | 149 | 9/26/2025 |
| 9.0.2 | 128 | 9/26/2025 |
| 9.0.1 | 286 | 8/8/2025 |
| 9.0.0 | 292 | 11/20/2024 |
| 8.0.1 | 186 | 11/14/2024 |
| 8.0.0 | 4,713 | 10/22/2024 |
| 7.0.8 | 5,741 | 2/16/2024 |
| 7.0.3 | 249 | 12/26/2023 |
| 4.0.1 | 550 | 12/13/2022 |
| 4.0.0 | 449 | 11/10/2022 |
| 3.0.0 | 1,039 | 11/29/2021 |
| 2.0.0 | 783 | 1/6/2020 |
| 1.0.0 | 725 | 1/6/2020 |
Upgraded to .net10