DevelopmentHelpers.AzureDistributedCache 10.0.0

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

DevelopmentHelpers.AzureDistributedCache

Overview

**DevelopmentHelpers.AzureDistributedCache is a library that simplifies access to Azure Redis Cache in .NET applications.

Installation

  1. Add Configuration Settings to your appsettings.json file:
    {
      "DevelopmentHelpers" : {
       "AzureDistributedCacheConfiguration": {
      "DnsName": "--DNS--NAME",
      "ConnectionString": "-- Connection String --- "
      }
     }
    }  
    
  2. 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 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

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