Microsoft.Extensions.Caching.Hybrid
9.0.0-preview.9.24556.5
Prefix Reserved
dotnet add package Microsoft.Extensions.Caching.Hybrid --version 9.0.0-preview.9.24556.5
NuGet\Install-Package Microsoft.Extensions.Caching.Hybrid -Version 9.0.0-preview.9.24556.5
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0-preview.9.24556.5" />
paket add Microsoft.Extensions.Caching.Hybrid --version 9.0.0-preview.9.24556.5
#r "nuget: Microsoft.Extensions.Caching.Hybrid, 9.0.0-preview.9.24556.5"
// Install Microsoft.Extensions.Caching.Hybrid as a Cake Addin #addin nuget:?package=Microsoft.Extensions.Caching.Hybrid&version=9.0.0-preview.9.24556.5&prerelease // Install Microsoft.Extensions.Caching.Hybrid as a Cake Tool #tool nuget:?package=Microsoft.Extensions.Caching.Hybrid&version=9.0.0-preview.9.24556.5&prerelease
Microsoft.Extensions.Caching.Hybrid
This package contains a concrete implementation of the HybridCache
API,
simplifying and enhancing cache usage that might previously have been built on top of IDistributedCache
.
Key features:
- built on top of
IDistributedCache
- all existing cache backends (Redis, SQL Server, CosmosDB, etc) should work immediately - simple API (all the cache, serialization, etc details from are encapsulated)
- cache-stampede protection (combining of concurrent requests for the same data)
- performance enhancements such as inbuilt support for the newer
IBufferDistributedCache
API - fully configurable serialization
Full HybridCache
documentation is here.
Full documentation
See learn.microsoft.com for full discussion of HybridCache
.
Install the package
From the command-line:
dotnet add package Microsoft.Extensions.Caching.Hybrid
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="[CURRENTVERSION]" />
</ItemGroup>
Usage example
The HybridCache
service can be registered and configured via IServiceCollection
, for example:
builder.Services.AddHybridCache(/* optional configuration /*);
Note that in many cases you may also wish to register a distributed cache backend, as discussed here; for example a Redis instance:
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = builder.Configuration.GetConnectionString("MyRedisConStr");
});
Once registered, the HybridCache
instance can be obtained via dependency-injection, allowing the
GetOrCreateAsync
API to be used to obtain data:
public class SomeService(HybridCache cache)
{
private HybridCache _cache = cache;
public async Task<SomeDataType> GetSomeInfoAsync(string name, int id, CancellationToken token = default)
{
return await _cache.GetOrCreateAsync(
$"{name}-{id}", // Unique key to the cache entry
async cancel => await GetDataFromTheSourceAsync(name, id, cancel),
cancellationToken: token
);
}
private async Task<SomeDataType> GetDataFromTheSourceAsync(string name, int id, CancellationToken token)
{
// talk to the underlying data store here - could be SQL, gRPC, HTTP, etc
}
}
Additional usage guidance - including expiration, custom serialization support, and alternate usage to reduce delegate allocation - is available on learn.microsoft.com.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.TimeProvider (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
.NETStandard 2.0
- Microsoft.Bcl.TimeProvider (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
.NETStandard 2.1
- Microsoft.Bcl.TimeProvider (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
net8.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
-
net9.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Microsoft.Extensions.Caching.Hybrid:
Package | Downloads |
---|---|
Volo.Abp.Caching
Package Description |
|
Altinn.App.Core
This class library holds all the core features used by a standard Altinn 3 App. |
|
Hexalith.Infrastructure.ClientAppOnServer
Hexalith is a set of libraries to build a micro-service architecture. |
|
Umbraco.Cms.PublishedCache.HybridCache
Contains the published cache assembly needed to run Umbraco CMS. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.Extensions.Caching.Hybrid:
Repository | Stars |
---|---|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
Version | Downloads | Last updated |
---|---|---|
9.0.0-preview.9.24556.5 | 5,585 | 11/12/2024 |
9.0.0-preview.9.24507.7 | 13,199 | 10/8/2024 |
9.0.0-preview.7.24406.2 | 34,423 | 8/13/2024 |
9.0.0-preview.6.24328.4 | 40,544 | 7/9/2024 |
9.0.0-preview.5.24306.11 | 26,388 | 6/11/2024 |
9.0.0-preview.4.24267.6 | 6,965 | 5/21/2024 |