From 0269de03646cb7f34e8d2840cd5ae832673aea04 Mon Sep 17 00:00:00 2001 From: Jared <85176005+JaredMSFT@users.noreply.github.com> Date: Mon, 4 Aug 2025 22:01:58 -0400 Subject: [PATCH 1/7] Update distributed.md adding Postgres cache --- aspnetcore/performance/caching/distributed.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index 71dffc0a5f76..e46a78d6657b 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -27,7 +27,7 @@ When cached data is distributed, the data: * Survives server restarts and app deployments. * Doesn't use local memory. -Distributed cache configuration is implementation specific. This article describes how to configure SQL Server and Redis distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)). Regardless of which implementation is selected, the app interacts with the cache using the interface. +Distributed cache configuration is implementation specific. This article describes how to configure SQL Server and Redis distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)), Cosmos DB, and Postgres. Regardless of which implementation is selected, the app interacts with the cache using the interface. [View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/performance/caching/distributed/samples/) ([how to download](xref:index#how-to-download-a-sample)) @@ -39,6 +39,8 @@ Add a package reference for the distributed cache provider used: * For a Redis distributed cache, [Microsoft.Extensions.Caching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis). * For SQL Server, [Microsoft.Extensions.Caching.SqlServer](https://www.nuget.org/packages/Microsoft.Extensions.Caching.SqlServer). +* For Postgres, [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres). +* For Cosmos DB, [Microsoft.Extensions.Caching.Cosmos](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Cosmos). * For the NCache distributed cache, [NCache.Microsoft.Extensions.Caching.OpenSource](https://www.nuget.org/packages/NCache.Microsoft.Extensions.Caching.OpenSource). ## IDistributedCache interface @@ -57,8 +59,9 @@ Register an implementation of [!NOTE] > A (and optionally, and ) are typically stored outside of source control (for example, stored by the [Secret Manager](xref:security/app-secrets) or in `appsettings.json`/`appsettings.{Environment}.json` files). The connection string may contain credentials that should be kept out of source control systems. +### Distributed Postgres Cache + +The Distributed Postgres Cache implementation () allows the distributed cache to use a Postgres database as its backing store. + ### Distributed NCache Cache [NCache](https://github.com/Alachisoft/NCache) is an open source in-memory distributed cache developed natively in .NET. NCache works both locally and configured as a distributed cache cluster for an ASP.NET Core app running in Azure or on other hosting platforms. @@ -140,7 +147,7 @@ To configure NCache: [!code-csharp[](~/performance/caching/distributed/samples/6.x/DistCacheSample/Program.cs?name=snippet_AddNCache_Cache)] -### Distributed Azure CosmosDB Cache +### Distributed Azure Cosmos DB Cache [Azure Cosmos DB](/azure/cosmos-db/introduction) can be used in ASP.NET Core as a session state provider by using the `IDistributedCache` interface. Azure Cosmos DB is a fully managed NoSQL and relational database for modern app development that offers high availability, scalability, and low-latency access to data for mission-critical applications. @@ -213,6 +220,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) +* [Postgres Database on Azure](/azure/postgres/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * [Repository README file for Microsoft.Extensions.Caching.Cosmos](https://github.com/Azure/Microsoft.Extensions.Caching.Cosmos/blob/master/README.md) * From daee8f0f88405ef6f318d2547356755f28f5e763 Mon Sep 17 00:00:00 2001 From: Jared <85176005+JaredMSFT@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:27:25 -0400 Subject: [PATCH 2/7] adding references to postgres distributed cache --- aspnetcore/fundamentals/app-state.md | 4 +- aspnetcore/performance/caching/distributed.md | 82 ++++++++++++++++- .../distributed/includes/distributed5.md | 90 ++++++++++++++++++- .../distributed/includes/distributed6-7.md | 89 +++++++++++++++++- aspnetcore/performance/caching/hybrid.md | 8 +- aspnetcore/performance/caching/overview.md | 2 +- .../caching/overview/includes/overview6.md | 2 +- .../caching/overview/includes/overview7-8.md | 2 +- aspnetcore/performance/caching/response.md | 2 +- .../aspnetcore-9/includes/hybrid-cache.md | 2 +- 10 files changed, 271 insertions(+), 12 deletions(-) diff --git a/aspnetcore/fundamentals/app-state.md b/aspnetcore/fundamentals/app-state.md index aaef80256af8..f1304dc68162 100644 --- a/aspnetcore/fundamentals/app-state.md +++ b/aspnetcore/fundamentals/app-state.md @@ -75,7 +75,7 @@ Session state exhibits the following behaviors: The in-memory cache provider stores session data in the memory of the server where the app resides. In a server farm scenario: -* Use *sticky sessions* to tie each session to a specific app instance on an individual server. [Azure App Service](https://azure.microsoft.com/services/app-service/) uses [Application Request Routing (ARR)](/iis/extensions/planning-for-arr/using-the-application-request-routing-module) to enforce sticky sessions by default. However, sticky sessions can affect scalability and complicate web app updates. A better approach is to use a Redis or SQL Server distributed cache, which doesn't require sticky sessions. For more information, see . +* Use *sticky sessions* to tie each session to a specific app instance on an individual server. [Azure App Service](https://azure.microsoft.com/services/app-service/) uses [Application Request Routing (ARR)](/iis/extensions/planning-for-arr/using-the-application-request-routing-module) to enforce sticky sessions by default. However, sticky sessions can affect scalability and complicate web app updates. A better approach is to use a Redis, SQL Server, or Azure Postgres distributed cache, which doesn't require sticky sessions. For more information, see . * The session cookie is encrypted via . Data Protection must be properly configured to read session cookies on each machine. For more information, see and [Key storage providers](xref:security/data-protection/implementation/key-storage-providers). ### Configure session state @@ -354,7 +354,7 @@ Session state exhibits the following behaviors: The in-memory cache provider stores session data in the memory of the server where the app resides. In a server farm scenario: -* Use *sticky sessions* to tie each session to a specific app instance on an individual server. [Azure App Service](https://azure.microsoft.com/services/app-service/) uses [Application Request Routing (ARR)](/iis/extensions/planning-for-arr/using-the-application-request-routing-module) to enforce sticky sessions by default. However, sticky sessions can affect scalability and complicate web app updates. A better approach is to use a Redis or SQL Server distributed cache, which doesn't require sticky sessions. For more information, see . +* Use *sticky sessions* to tie each session to a specific app instance on an individual server. [Azure App Service](https://azure.microsoft.com/services/app-service/) uses [Application Request Routing (ARR)](/iis/extensions/planning-for-arr/using-the-application-request-routing-module) to enforce sticky sessions by default. However, sticky sessions can affect scalability and complicate web app updates. A better approach is to use a Redis, SQL Server, or Azure Postgres distributed cache, which doesn't require sticky sessions. For more information, see . * The session cookie is encrypted via . Data Protection must be properly configured to read session cookies on each machine. For more information, see and [Key storage providers](xref:security/data-protection/implementation/key-storage-providers). ### Configure session state diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index e46a78d6657b..005958fb5618 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -61,7 +61,7 @@ Register an implementation of ) allows the distributed cache to use a Postgres database as its backing store. +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: + +1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: + +```json + "ConnectionStrings": { + "PostgresCache": "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=yourdatabase;Pooling=true;MinPoolSize=0;MaxPoolSize=100;Timeout=15;" + }, + "PostgresCache": { + "SchemaName": "public", + "TableName": "cache", + "CreateIfNotExists": true, + "UseWAL": false, + "ExpiredItemsDeletionInterval": "00:30:00", + "DefaultSlidingExpiration": "00:20:00" + } +``` +2. Register the Service + +```csharp +using Microsoft.Extensions.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); + +// Register Postgres distributed cache +builder.Services.AddDistributedPostgresCache(options => { + options.ConnectionString = builder.Configuration.GetConnectionString("PostgresCache"); + options.SchemaName = builder.Configuration.GetValue("PostgresCache:SchemaName", "public"); + options.TableName = builder.Configuration.GetValue("PostgresCache:TableName", "cache"); + options.CreateIfNotExists = builder.Configuration.GetValue("PostgresCache:CreateIfNotExists", true); + options.UseWAL = builder.Configuration.GetValue("PostgresCache:UseWAL", false); + + // Optional: Configure expiration settings + + var expirationInterval = builder.Configuration.GetValue("PostgresCache:ExpiredItemsDeletionInterval"); + if (!string.IsNullOrEmpty(expirationInterval) && TimeSpan.TryParse(expirationInterval, out var interval)) { + options.ExpiredItemsDeletionInterval = interval; + } + + var slidingExpiration = builder.Configuration.GetValue("PostgresCache:DefaultSlidingExpiration"); + if (!string.IsNullOrEmpty(slidingExpiration) && TimeSpan.TryParse(slidingExpiration, out var sliding)) { + options.DefaultSlidingExpiration = sliding; + } +}); + +var app = builder.Build(); +``` + +3. Use the Cache + +```csharp +public class MyService { + private readonly IDistributedCache _cache; + + public MyService(IDistributedCache cache) { + _cache = cache; + } + + public async Task GetDataAsync(string key) { + var cachedData = await _cache.GetStringAsync(key); + + if (cachedData == null) { + // Fetch data from source + var data = await FetchDataFromSource(); + + // Cache the data with options + var options = new DistributedCacheEntryOptions { + AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30), + SlidingExpiration = TimeSpan.FromMinutes(5) + }; + + await _cache.SetStringAsync(key, data, options); + return data; + } + + return cachedData; + } +} +``` + ### Distributed NCache Cache [NCache](https://github.com/Alachisoft/NCache) is an open source in-memory distributed cache developed natively in .NET. NCache works both locally and configured as a distributed cache cluster for an ASP.NET Core app running in Azure or on other hosting platforms. diff --git a/aspnetcore/performance/caching/distributed/includes/distributed5.md b/aspnetcore/performance/caching/distributed/includes/distributed5.md index ead82e603fd0..32bd2ce15bb7 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed5.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed5.md @@ -11,7 +11,7 @@ When cached data is distributed, the data: * Survives server restarts and app deployments. * Doesn't use local memory. -Distributed cache configuration is implementation specific. This article describes how to configure SQL Server and Redis distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)). Regardless of which implementation is selected, the app interacts with the cache using the interface. +Distributed cache configuration is implementation specific. This article describes how to configure SQL Server, Redis, and Postgres distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)). Regardless of which implementation is selected, the app interacts with the cache using the interface. [View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/performance/caching/distributed/samples/) ([how to download](xref:index#how-to-download-a-sample)) @@ -21,6 +21,8 @@ To use a SQL Server distributed cache, add a package reference to the [Microsoft To use a Redis distributed cache, add a package reference to the [Microsoft.Extensions.Caching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis) package. +To use a Postgres distributed cache, add a package reference to the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) package. + To use NCache distributed cache, add a package reference to the [NCache.Microsoft.Extensions.Caching.OpenSource](https://www.nuget.org/packages/NCache.Microsoft.Extensions.Caching.OpenSource) package. ## IDistributedCache interface @@ -39,6 +41,7 @@ Register an implementation of ) allows the distributed cache to use a Postgres database as its backing store. + +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: + +1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: + +```json + "ConnectionStrings": { + "PostgresCache": "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=yourdatabase;Pooling=true;MinPoolSize=0;MaxPoolSize=100;Timeout=15;" + }, + "PostgresCache": { + "SchemaName": "public", + "TableName": "cache", + "CreateIfNotExists": true, + "UseWAL": false, + "ExpiredItemsDeletionInterval": "00:30:00", + "DefaultSlidingExpiration": "00:20:00" + } +``` +2. Register the Service + +```csharp +using Microsoft.Extensions.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); + +// Register Postgres distributed cache +builder.Services.AddDistributedPostgresCache(options => { + options.ConnectionString = builder.Configuration.GetConnectionString("PostgresCache"); + options.SchemaName = builder.Configuration.GetValue("PostgresCache:SchemaName", "public"); + options.TableName = builder.Configuration.GetValue("PostgresCache:TableName", "cache"); + options.CreateIfNotExists = builder.Configuration.GetValue("PostgresCache:CreateIfNotExists", true); + options.UseWAL = builder.Configuration.GetValue("PostgresCache:UseWAL", false); + + // Optional: Configure expiration settings + + var expirationInterval = builder.Configuration.GetValue("PostgresCache:ExpiredItemsDeletionInterval"); + if (!string.IsNullOrEmpty(expirationInterval) && TimeSpan.TryParse(expirationInterval, out var interval)) { + options.ExpiredItemsDeletionInterval = interval; + } + + var slidingExpiration = builder.Configuration.GetValue("PostgresCache:DefaultSlidingExpiration"); + if (!string.IsNullOrEmpty(slidingExpiration) && TimeSpan.TryParse(slidingExpiration, out var sliding)) { + options.DefaultSlidingExpiration = sliding; + } +}); + +var app = builder.Build(); +``` + +3. Use the Cache + +```csharp +public class MyService { + private readonly IDistributedCache _cache; + + public MyService(IDistributedCache cache) { + _cache = cache; + } + + public async Task GetDataAsync(string key) { + var cachedData = await _cache.GetStringAsync(key); + + if (cachedData == null) { + // Fetch data from source + var data = await FetchDataFromSource(); + + // Cache the data with options + var options = new DistributedCacheEntryOptions { + AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30), + SlidingExpiration = TimeSpan.FromMinutes(5) + }; + + await _cache.SetStringAsync(key, data, options); + return data; + } + + return cachedData; + } +} +``` + ### Distributed NCache Cache [NCache](https://github.com/Alachisoft/NCache) is an open source in-memory distributed cache developed natively in .NET and .NET Core. NCache works both locally and configured as a distributed cache cluster for an ASP.NET Core app running in Azure or on other hosting platforms. @@ -166,6 +253,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) +* [Azure Postgres](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * * diff --git a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md index 8d066458a20f..b71db219b979 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md @@ -11,7 +11,7 @@ When cached data is distributed, the data: * Survives server restarts and app deployments. * Doesn't use local memory. -Distributed cache configuration is implementation specific. This article describes how to configure SQL Server and Redis distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)). Regardless of which implementation is selected, the app interacts with the cache using the interface. +Distributed cache configuration is implementation specific. This article describes how to configure SQL Server, Redis, and Postgres distributed caches. Third party implementations are also available, such as [NCache](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)). Regardless of which implementation is selected, the app interacts with the cache using the interface. [View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/performance/caching/distributed/samples/) ([how to download](xref:index#how-to-download-a-sample)) @@ -21,6 +21,7 @@ Add a package reference for the distributed cache provider used: * For a Redis distributed cache, [Microsoft.Extensions.Caching.StackExchangeRedis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis). * For SQL Server, [Microsoft.Extensions.Caching.SqlServer](https://www.nuget.org/packages/Microsoft.Extensions.Caching.SqlServer). +* For Postgres, [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres). * For the NCache distributed cache, [NCache.Microsoft.Extensions.Caching.OpenSource](https://www.nuget.org/packages/NCache.Microsoft.Extensions.Caching.OpenSource). * [!INCLUDE [managed-identities](~/includes/managed-identities-test-non-production.md)] @@ -41,6 +42,7 @@ Register an implementation of [!NOTE] > A (and optionally, and ) are typically stored outside of source control (for example, stored by the [Secret Manager](xref:security/app-secrets) or in `appsettings.json`/`appsettings.{Environment}.json` files). The connection string may contain credentials that should be kept out of source control systems. +### Distributed Postgres Cache + +The Distributed Postgres Cache implementation () allows the distributed cache to use a Postgres database as its backing store. + +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: + +1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: + +```json + "ConnectionStrings": { + "PostgresCache": "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=yourdatabase;Pooling=true;MinPoolSize=0;MaxPoolSize=100;Timeout=15;" + }, + "PostgresCache": { + "SchemaName": "public", + "TableName": "cache", + "CreateIfNotExists": true, + "UseWAL": false, + "ExpiredItemsDeletionInterval": "00:30:00", + "DefaultSlidingExpiration": "00:20:00" + } +``` +2. Register the Service + +```csharp +using Microsoft.Extensions.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); + +// Register Postgres distributed cache +builder.Services.AddDistributedPostgresCache(options => { + options.ConnectionString = builder.Configuration.GetConnectionString("PostgresCache"); + options.SchemaName = builder.Configuration.GetValue("PostgresCache:SchemaName", "public"); + options.TableName = builder.Configuration.GetValue("PostgresCache:TableName", "cache"); + options.CreateIfNotExists = builder.Configuration.GetValue("PostgresCache:CreateIfNotExists", true); + options.UseWAL = builder.Configuration.GetValue("PostgresCache:UseWAL", false); + + // Optional: Configure expiration settings + + var expirationInterval = builder.Configuration.GetValue("PostgresCache:ExpiredItemsDeletionInterval"); + if (!string.IsNullOrEmpty(expirationInterval) && TimeSpan.TryParse(expirationInterval, out var interval)) { + options.ExpiredItemsDeletionInterval = interval; + } + + var slidingExpiration = builder.Configuration.GetValue("PostgresCache:DefaultSlidingExpiration"); + if (!string.IsNullOrEmpty(slidingExpiration) && TimeSpan.TryParse(slidingExpiration, out var sliding)) { + options.DefaultSlidingExpiration = sliding; + } +}); + +var app = builder.Build(); +``` + +3. Use the Cache + +```csharp +public class MyService { + private readonly IDistributedCache _cache; + + public MyService(IDistributedCache cache) { + _cache = cache; + } + + public async Task GetDataAsync(string key) { + var cachedData = await _cache.GetStringAsync(key); + + if (cachedData == null) { + // Fetch data from source + var data = await FetchDataFromSource(); + + // Cache the data with options + var options = new DistributedCacheEntryOptions { + AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30), + SlidingExpiration = TimeSpan.FromMinutes(5) + }; + + await _cache.SetStringAsync(key, data, options); + return data; + } + + return cachedData; + } +} +``` + ### Distributed NCache Cache [NCache](https://github.com/Alachisoft/NCache) is an open source in-memory distributed cache developed natively in .NET and .NET Core. NCache works both locally and configured as a distributed cache cluster for an ASP.NET Core app running in Azure or on other hosting platforms. @@ -162,6 +248,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) +* [Azure Postgres](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * * diff --git a/aspnetcore/performance/caching/hybrid.md b/aspnetcore/performance/caching/hybrid.md index 23cc0bfda24c..316fb920682a 100644 --- a/aspnetcore/performance/caching/hybrid.md +++ b/aspnetcore/performance/caching/hybrid.md @@ -165,7 +165,7 @@ The following example configures the service to use a general-purpose protobuf s :::code language="csharp" source="~/performance/caching/hybrid/samples/9.x/HCMinimal2/Program.cs" id="snippet_withserializerfactory" highlight="14"::: -The secondary cache requires a data store, such as Redis or SqlServer. To use [Azure Cache for Redis](https://azure.microsoft.com/products/cache), for example: +The secondary cache requires a data store, such as Redis, Sql Server, or Postgres. To use [Azure Cache for Redis](https://azure.microsoft.com/products/cache), for example: * Install the `Microsoft.Extensions.Caching.StackExchangeRedis` package. * Create an instance of Azure Cache for Redis. @@ -217,7 +217,7 @@ In such cases, inform `HybridCache` that it's safe to reuse instances by making ### Avoid `byte[]` allocations -`HybridCache` also provides optional APIs for `IDistributedCache` implementations, to avoid `byte[]` allocations. This feature is implemented by the preview versions of the `Microsoft.Extensions.Caching.StackExchangeRedis` and `Microsoft.Extensions.Caching.SqlServer` packages. For more information, see . +`HybridCache` also provides optional APIs for `IDistributedCache` implementations, to avoid `byte[]` allocations. This feature is implemented by the preview versions of the `Microsoft.Extensions.Caching.StackExchangeRedis`, `Microsoft.Extensions.Caching.SqlServer`, and `Microsoft.Extensions.Caching.Postgres` packages. For more information, see . Here are the .NET CLI commands to install the packages: ```dotnetcli @@ -228,6 +228,10 @@ dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis dotnet add package Microsoft.Extensions.Caching.SqlServer ``` +```dotnetcli +dotnet add package Microsoft.Extensions.Caching.Postgres +``` + ## Custom HybridCache implementations A concrete implementation of the `HybridCache` abstract class is included in the shared framework and is provided via dependency injection. But developers are welcome to provide or consume custom implementations of the API, for example [FusionCache](https://github.com/ZiggyCreatures/FusionCache/blob/main/docs/MicrosoftHybridCache.md). diff --git a/aspnetcore/performance/caching/overview.md b/aspnetcore/performance/caching/overview.md index 7f41917034f6..3b03544470e1 100644 --- a/aspnetcore/performance/caching/overview.md +++ b/aspnetcore/performance/caching/overview.md @@ -23,7 +23,7 @@ For more information, see and [Troubleshoot Az ## Distributed Cache -Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. +Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), [Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. For more information, see . diff --git a/aspnetcore/performance/caching/overview/includes/overview6.md b/aspnetcore/performance/caching/overview/includes/overview6.md index 1e1404ceb4bc..cf4eb06cfa3a 100644 --- a/aspnetcore/performance/caching/overview/includes/overview6.md +++ b/aspnetcore/performance/caching/overview/includes/overview6.md @@ -8,7 +8,7 @@ For more information, see and [Troubleshoot Az ## Distributed Cache -Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. +Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), [Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. For more information, see . diff --git a/aspnetcore/performance/caching/overview/includes/overview7-8.md b/aspnetcore/performance/caching/overview/includes/overview7-8.md index b714ffbca6ab..9594865fb465 100644 --- a/aspnetcore/performance/caching/overview/includes/overview7-8.md +++ b/aspnetcore/performance/caching/overview/includes/overview7-8.md @@ -8,7 +8,7 @@ For more information, see and [Troubleshoot Az ## Distributed Cache -Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. +Use a distributed cache to store data when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), [Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. For more information, see . diff --git a/aspnetcore/performance/caching/response.md b/aspnetcore/performance/caching/response.md index fa7bc725b0ec..8dcbbaa35a0d 100644 --- a/aspnetcore/performance/caching/response.md +++ b/aspnetcore/performance/caching/response.md @@ -245,7 +245,7 @@ For more information, see and [Troubleshoot Az ### Distributed Cache -Use a distributed cache to store data in memory when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. +Use a distributed cache to store data in memory when the app is hosted in a cloud or server farm. The cache is shared across the servers that process requests. A client can submit a request that's handled by any server in the group if cached data for the client is available. ASP.NET Core works with SQL Server, [Redis](https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis), [Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres), and [NCache](https://www.nuget.org/packages/Alachisoft.NCache.OpenSource.SDK/) distributed caches. For more information, see . diff --git a/aspnetcore/release-notes/aspnetcore-9/includes/hybrid-cache.md b/aspnetcore/release-notes/aspnetcore-9/includes/hybrid-cache.md index ea0cd27e10d6..6a288d263745 100644 --- a/aspnetcore/release-notes/aspnetcore-9/includes/hybrid-cache.md +++ b/aspnetcore/release-notes/aspnetcore-9/includes/hybrid-cache.md @@ -126,7 +126,7 @@ By reusing instances, `HybridCache` can reduce the overhead of CPU and object al Like `IDistributedCache`, `HybridCache` supports removal by key with a `RemoveKeyAsync` method. `HybridCache` also provides optional APIs for `IDistributedCache` implementations, to avoid `byte[]` allocations. This feature is implemented -by the preview versions of the `Microsoft.Extensions.Caching.StackExchangeRedis` and `Microsoft.Extensions.Caching.SqlServer` packages. +by the preview versions of the `Microsoft.Extensions.Caching.StackExchangeRedis`, `Microsoft.Extensions.Caching.SqlServer`, and `Microsoft.Extensions.Caching.Postgres` packages. Serialization is configured as part of registering the service, with support for type-specific and generalized serializers via the `WithSerializer` and `.WithSerializerFactory` methods, chained from the `AddHybridCache` call. By default, the library From 73f94bcf7c6f5fcf0e5d15c47599c72ea3efe29d Mon Sep 17 00:00:00 2001 From: Jared <85176005+JaredMSFT@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:40:17 -0400 Subject: [PATCH 3/7] corrected build service warnings --- aspnetcore/performance/caching/distributed.md | 2 +- .../performance/caching/distributed/includes/distributed5.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index 005958fb5618..389c8aa81fd1 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -300,7 +300,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) -* [Postgres Database on Azure](/azure/postgres/) +* [Postgres Database on Azure](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * [Repository README file for Microsoft.Extensions.Caching.Cosmos](https://github.com/Azure/Microsoft.Extensions.Caching.Cosmos/blob/master/README.md) * diff --git a/aspnetcore/performance/caching/distributed/includes/distributed5.md b/aspnetcore/performance/caching/distributed/includes/distributed5.md index 32bd2ce15bb7..168b124c362d 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed5.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed5.md @@ -41,7 +41,7 @@ Register an implementation of Date: Tue, 5 Aug 2025 10:51:15 -0400 Subject: [PATCH 4/7] updated link text to match product title --- aspnetcore/performance/caching/distributed.md | 2 +- .../performance/caching/distributed/includes/distributed5.md | 2 +- .../performance/caching/distributed/includes/distributed6-7.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index 389c8aa81fd1..0d4f61c0efc7 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -300,7 +300,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) -* [Postgres Database on Azure](/azure/postgresql/) +* [Azure Database for PostgreSQL](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * [Repository README file for Microsoft.Extensions.Caching.Cosmos](https://github.com/Azure/Microsoft.Extensions.Caching.Cosmos/blob/master/README.md) * diff --git a/aspnetcore/performance/caching/distributed/includes/distributed5.md b/aspnetcore/performance/caching/distributed/includes/distributed5.md index 168b124c362d..de52e03373e9 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed5.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed5.md @@ -253,7 +253,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) -* [Azure Postgres](/azure/postgresql/) +* [Azure Database for PostgreSQL](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * * diff --git a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md index b71db219b979..381282fb017c 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md @@ -248,7 +248,7 @@ When SQL Server is used as a distributed cache backing store, use of the same da * [Redis Cache on Azure](/azure/azure-cache-for-redis/) * [SQL Database on Azure](/azure/sql-database/) -* [Azure Postgres](/azure/postgresql/) +* [Azure Database for PostgreSQL](/azure/postgresql/) * [ASP.NET Core IDistributedCache Provider for NCache in Web Farms](http://www.alachisoft.com/ncache/aspnet-core-idistributedcache-ncache.html) ([NCache on GitHub](https://github.com/Alachisoft/NCache)) * * From 31eae3bab23883a3357ffe6fb8605d4c732d4543 Mon Sep 17 00:00:00 2001 From: Jared <85176005+JaredMSFT@users.noreply.github.com> Date: Thu, 7 Aug 2025 15:19:21 -0400 Subject: [PATCH 5/7] removed xref and added correct links --- aspnetcore/performance/caching/distributed.md | 4 ++-- .../performance/caching/distributed/includes/distributed5.md | 4 ++-- .../caching/distributed/includes/distributed6-7.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index 0d4f61c0efc7..3b991f85f717 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -131,9 +131,9 @@ The sample app implements ) allows the distributed cache to use a Postgres database as its backing store. +[Azure Database for PostgreSQL](/azure/postgresql) can be used as a distributed cache backing store via the `IDistributedCache` interface. Azure Database for PostgreSQL is a fully managed, AI-ready Database-as-a-Service (DBaaS) offering built on the open-source PostgreSQL engine, designed to support mission-critical workloads with predictable performance, robust security, high availability, and seamless scalability. -After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure your distributed cache as follows: 1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: diff --git a/aspnetcore/performance/caching/distributed/includes/distributed5.md b/aspnetcore/performance/caching/distributed/includes/distributed5.md index de52e03373e9..a92264292262 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed5.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed5.md @@ -110,9 +110,9 @@ See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/19542) ### Distributed Postgres Cache -The Distributed Postgres Cache implementation () allows the distributed cache to use a Postgres database as its backing store. +[Azure Database for PostgreSQL](/azure/postgresql) can be used as a distributed cache backing store via the `IDistributedCache` interface. Azure Database for PostgreSQL is a fully managed, AI-ready Database-as-a-Service (DBaaS) offering built on the open-source PostgreSQL engine, designed to support mission-critical workloads with predictable performance, robust security, high availability, and seamless scalability. -After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure your distributed cache as follows: 1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: diff --git a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md index 381282fb017c..d4c3c16c844c 100644 --- a/aspnetcore/performance/caching/distributed/includes/distributed6-7.md +++ b/aspnetcore/performance/caching/distributed/includes/distributed6-7.md @@ -113,9 +113,9 @@ The sample app implements ) allows the distributed cache to use a Postgres database as its backing store. +[Azure Database for PostgreSQL](/azure/postgresql) can be used as a distributed cache backing store via the `IDistributedCache` interface. Azure Database for PostgreSQL is a fully managed, AI-ready Database-as-a-Service (DBaaS) offering built on the open-source PostgreSQL engine, designed to support mission-critical workloads with predictable performance, robust security, high availability, and seamless scalability. -After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure an Azure Postgres distributed cache as follows: +After installing the [Microsoft.Extensions.Caching.Postgres](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Postgres) NuGet package, configure your distributed cache as follows: 1. Add the following configuration sections to your appsettings.json file. It's also recommended to configure your connection string to use connection pooling: From 3f476b473653386cc9d67d701613c3fa8ac67dc2 Mon Sep 17 00:00:00 2001 From: Jared <85176005+JaredMSFT@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:51:52 -0400 Subject: [PATCH 6/7] simplified content, configuration values don't need to be from appsettings.json --- aspnetcore/performance/caching/distributed.md | 17 +---------------- .../distributed/includes/distributed5.md | 17 +---------------- .../distributed/includes/distributed6-7.md | 17 +---------------- 3 files changed, 3 insertions(+), 48 deletions(-) diff --git a/aspnetcore/performance/caching/distributed.md b/aspnetcore/performance/caching/distributed.md index 3b991f85f717..7b4310f47a30 100644 --- a/aspnetcore/performance/caching/distributed.md +++ b/aspnetcore/performance/caching/distributed.md @@ -135,22 +135,7 @@ The sample app implements Date: Fri, 8 Aug 2025 12:16:43 -0700 Subject: [PATCH 7/7] Update aspnetcore/performance/caching/hybrid.md Sql Server > SQL Server typo fix. --- aspnetcore/performance/caching/hybrid.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/performance/caching/hybrid.md b/aspnetcore/performance/caching/hybrid.md index 316fb920682a..113db63f4efa 100644 --- a/aspnetcore/performance/caching/hybrid.md +++ b/aspnetcore/performance/caching/hybrid.md @@ -165,7 +165,7 @@ The following example configures the service to use a general-purpose protobuf s :::code language="csharp" source="~/performance/caching/hybrid/samples/9.x/HCMinimal2/Program.cs" id="snippet_withserializerfactory" highlight="14"::: -The secondary cache requires a data store, such as Redis, Sql Server, or Postgres. To use [Azure Cache for Redis](https://azure.microsoft.com/products/cache), for example: +The secondary cache requires a data store, such as Redis, SQL Server, or Postgres. To use [Azure Cache for Redis](https://azure.microsoft.com/products/cache), for example: * Install the `Microsoft.Extensions.Caching.StackExchangeRedis` package. * Create an instance of Azure Cache for Redis.