dotnet add package Microsoft.Extensions.Caching.Memory --version 9.0.10
NuGet\Install-Package Microsoft.Extensions.Caching.Memory -Version 9.0.10
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.10" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.10" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
paket add Microsoft.Extensions.Caching.Memory --version 9.0.10
#r "nuget: Microsoft.Extensions.Caching.Memory, 9.0.10"
#:package Microsoft.Extensions.Caching.Memory@9.0.10
#addin nuget:?package=Microsoft.Extensions.Caching.Memory&version=9.0.10
#tool nuget:?package=Microsoft.Extensions.Caching.Memory&version=9.0.10
Provides implementations for local and distributed in-memory cache. It stores and retrieves data in a fast and efficient way.
Use Microsoft.Extensions.Caching.Memory over System.Runtime.Caching when working with ASP.NET Core as it provides better integration support. For example, IMemoryCache works natively with ASP.NET Core dependency injection.
Local in-memory serialization:
using Microsoft.Extensions.Caching.Memory;
using MemoryCache cache = new(new MemoryCacheOptions());
object valueToCache = new();
string key = "key";
using (ICacheEntry entry = cache.CreateEntry(key))
{
// Entries are committed after they are disposed therefore it does not exist yet.
Console.WriteLine($"Exists: {cache.TryGetValue(key, out _)}\n");
entry.Value = valueToCache;
entry.SlidingExpiration = TimeSpan.FromSeconds(2);
}
bool exists = cache.TryGetValue(key, out object? cachedValue);
Console.WriteLine($"Exists: {exists}" );
Console.WriteLine($"cachedValue is valueToCache? {object.ReferenceEquals(cachedValue, valueToCache)}\n");
Console.WriteLine("Wait for the sliding expiration...");
Thread.Sleep(TimeSpan.FromSeconds(2));
Console.WriteLine("Exists: " + cache.TryGetValue(key, out _));
// You can also use the acceleration extensions to set and get entries
string key2 = "key2";
object value2 = new();
cache.Set("key2", value2);
object? cachedValue2 = cache.Get(key2);
Console.WriteLine($"cachedValue2 is value2? {object.ReferenceEquals(cachedValue2, value2)}");
The main types provided by this library are:
Microsoft.Extensions.Caching.Memory.MemoryCache
Microsoft.Extensions.Caching.Memory.MemoryCacheOptions
Microsoft.Extensions.Caching.Distributed.MemoryDistributedCache
Microsoft.Extensions.Caching.Memory.MemoryDistributedCacheOptions
Microsoft.Extensions.Caching.Abstractions
Microsoft.Extensions.Caching.Memory is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
.NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
.NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
MonoAndroid | monoandroid monoandroid was computed. |
MonoMac | monomac monomac was computed. |
MonoTouch | monotouch monotouch was computed. |
Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
Xamarin.iOS | xamarinios xamarinios was computed. |
Xamarin.Mac | xamarinmac xamarinmac was computed. |
Xamarin.TVOS | xamarintvos xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Caching.Memory:
Package | Downloads |
---|---|
Microsoft.EntityFrameworkCore
Entity Framework Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. EF Core works with SQL Server, Azure SQL Database, SQLite, Azure Cosmos DB, MySQL, PostgreSQL, and other databases through a provider plugin API. Commonly Used Types: Microsoft.EntityFrameworkCore.DbContext Microsoft.EntityFrameworkCore.DbSet |
|
Microsoft.EntityFrameworkCore.Relational
Shared Entity Framework Core components for relational database providers. |
|
Microsoft.Data.SqlClient
The current data provider for SQL Server and Azure SQL databases. This has replaced System.Data.SqlClient. These classes provide access to SQL and encapsulate database-specific protocols, including tabular data stream (TDS). Commonly Used Types: Microsoft.Data.SqlClient.SqlConnection Microsoft.Data.SqlClient.SqlException Microsoft.Data.SqlClient.SqlParameter Microsoft.Data.SqlClient.SqlDataReader Microsoft.Data.SqlClient.SqlCommand Microsoft.Data.SqlClient.SqlTransaction Microsoft.Data.SqlClient.SqlParameterCollection Microsoft.Data.SqlClient.SqlClientFactory When using NuGet 3.x this package requires at least version 3.4. |
|
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core. |
|
Microsoft.EntityFrameworkCore.Design
Shared design-time components for Entity Framework Core tools. |
Showing the top 20 popular GitHub repositories that depend on Microsoft.Extensions.Caching.Memory:
Repository | Stars |
---|---|
jellyfin/jellyfin
The Free Software Media System - Server Backend & API
|
|
bitwarden/server
Bitwarden infrastructure/backend (API, database, Docker, etc).
|
|
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
|
|
App-vNext/Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
duplicati/duplicati
Store securely encrypted backups in the cloud!
|
|
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
|
|
Flow-Launcher/Flow.Launcher
:mag: Quick file search & app launcher for Windows with community-made plugins
|
|
JeffreySu/WeiXinMPSDK
微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
|
|
ThreeMammals/Ocelot
.NET API Gateway
|
|
MassTransit/MassTransit
Distributed Application Framework for .NET
|
|
elsa-workflows/elsa-core
A .NET workflows library
|
|
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
|
|
graphql-dotnet/graphql-dotnet
GraphQL for .NET
|
|
DotNetNext/SqlSugar
.Net aot ORM SqlServer ORM Mongodb ORM MySql 瀚高 Postgresql ORM DB2 Hana 高斯 Duckdb C# VB.NET Sqlite ORM Oracle ORM Mysql Orm 虚谷数据库 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET9 ORM .NET8 ORM ClickHouse ORM QuestDb ,TDengine ORM,OceanBase ORM,GaussDB ORM,Tidb ORM Object/Relational Mapping
|
|
ChilliCream/graphql-platform
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Nitro the awesome Monaco based GraphQL IDE.
|
|
aspnet/Mvc
[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
|
|
anjoy8/Blog.Core
💖 ASP.NET Core 8.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
|
|
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
|
|
openiddict/openiddict-core
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
|
Version | Downloads | Last Updated | |
---|---|---|---|
10.0.0-rc.2.25502.107 | 0 | 10/14/2025 | |
10.0.0-rc.1.25451.107 | 66,441 | 9/9/2025 | |
10.0.0-preview.7.25380.108 | 31,816 | 8/12/2025 | |
10.0.0-preview.6.25358.103 | 12,991 | 7/15/2025 | |
10.0.0-preview.5.25277.114 | 46,723 | 6/6/2025 | |
10.0.0-preview.4.25258.110 | 31,135 | 5/12/2025 | |
10.0.0-preview.3.25171.5 | 24,924 | 4/10/2025 | |
10.0.0-preview.2.25163.2 | 11,498 | 3/18/2025 | |
10.0.0-preview.1.25080.5 | 16,404 | 2/25/2025 | |
9.0.10 | 0 | 10/14/2025 | |
9.0.9 | 4,107,164 | 9/9/2025 | |
9.0.8 | 6,499,730 | 8/4/2025 | |
9.0.7 | 5,909,093 | 7/8/2025 | |
9.0.6 | 7,308,339 | 6/10/2025 | |
9.0.5 | 9,265,787 | 5/13/2025 | |
9.0.4 | 17,612,614 | 4/8/2025 | |
9.0.3 | 9,692,688 | 3/11/2025 | |
9.0.2 | 12,055,747 | 2/11/2025 | |
9.0.1 | 20,946,269 | 1/14/2025 | |
9.0.0 | 42,856,035 | 11/12/2024 | |
9.0.0-rc.2.24473.5 | 816,695 | 10/8/2024 | |
9.0.0-rc.1.24431.7 | 342,509 | 9/10/2024 | |
9.0.0-preview.7.24405.7 | 662,308 | 8/13/2024 | |
9.0.0-preview.6.24327.7 | 348,570 | 7/9/2024 | |
9.0.0-preview.5.24306.7 | 115,972 | 6/11/2024 | |
9.0.0-preview.4.24266.19 | 92,895 | 5/21/2024 | |
9.0.0-preview.3.24172.9 | 225,384 | 4/11/2024 | |
9.0.0-preview.2.24128.5 | 100,719 | 3/12/2024 | |
9.0.0-preview.1.24080.9 | 145,867 | 2/13/2024 | |
8.0.1 | 132,264,561 | 10/8/2024 | |
8.0.0 | 203,310,537 | 11/14/2023 | |
8.0.0-rc.2.23479.6 | 1,733,502 | 10/10/2023 | |
8.0.0-rc.1.23419.4 | 429,237 | 9/12/2023 | |
8.0.0-preview.7.23375.6 | 590,421 | 8/8/2023 | |
8.0.0-preview.6.23329.7 | 239,122 | 7/11/2023 | |
8.0.0-preview.5.23280.8 | 217,067 | 6/13/2023 | |
8.0.0-preview.4.23259.5 | 156,311 | 5/16/2023 | |
8.0.0-preview.3.23174.8 | 298,272 | 4/11/2023 | |
8.0.0-preview.2.23128.3 | 215,883 | 3/14/2023 | |
8.0.0-preview.1.23110.8 | 145,051 | 2/21/2023 | |
7.0.0 | 173,568,268 | 11/7/2022 | |
7.0.0-rc.2.22472.3 | 256,702 | 10/11/2022 | |
7.0.0-rc.1.22426.10 | 260,043 | 9/14/2022 | |
7.0.0-preview.7.22375.6 | 119,492 | 8/9/2022 | |
7.0.0-preview.6.22324.4 | 84,785 | 7/12/2022 | |
7.0.0-preview.5.22301.12 | 71,903 | 6/14/2022 | |
7.0.0-preview.4.22229.4 | 85,449 | 5/10/2022 | |
7.0.0-preview.3.22175.4 | 81,618 | 4/13/2022 | |
7.0.0-preview.2.22152.2 | 90,375 | 3/14/2022 | |
7.0.0-preview.1.22076.8 | 77,033 | 2/17/2022 | |
6.0.3 | 3,756,331 | 11/12/2024 | |
6.0.2 | 4,536,037 | 10/8/2024 | |
6.0.1 | 258,271,559 | 2/8/2022 | |
6.0.0 | 134,327,364 | 11/8/2021 | |
6.0.0-rc.2.21480.5 | 535,823 | 10/12/2021 | |
6.0.0-rc.1.21451.13 | 288,464 | 9/14/2021 | |
6.0.0-preview.7.21377.19 | 106,431 | 8/10/2021 | |
6.0.0-preview.6.21352.12 | 51,568 | 7/14/2021 | |
6.0.0-preview.5.21301.5 | 196,251 | 6/15/2021 | |
6.0.0-preview.4.21253.7 | 95,177 | 5/24/2021 | |
6.0.0-preview.3.21201.4 | 107,794 | 4/8/2021 | |
6.0.0-preview.2.21154.6 | 76,616 | 3/11/2021 | |
6.0.0-preview.1.21102.12 | 370,993 | 2/12/2021 | |
5.0.0 | 195,411,181 | 11/9/2020 | |
5.0.0-rc.2.20475.5 | 396,664 | 10/13/2020 | |
5.0.0-rc.1.20451.14 | 331,856 | 9/14/2020 | |
5.0.0-preview.8.20407.11 | 211,418 | 8/25/2020 | |
5.0.0-preview.7.20364.11 | 123,788 | 7/21/2020 | |
5.0.0-preview.6.20305.6 | 59,389 | 6/25/2020 | |
5.0.0-preview.5.20278.1 | 7,004 | 6/10/2020 | |
5.0.0-preview.4.20251.6 | 202,567 | 5/18/2020 | |
5.0.0-preview.3.20215.2 | 121,441 | 4/23/2020 | |
5.0.0-preview.2.20160.3 | 115,126 | 4/2/2020 | |
5.0.0-preview.1.20120.4 | 62,727 | 3/16/2020 | |
3.1.32 | 9,232,972 | 12/13/2022 | |
3.1.31 | 2,009,947 | 11/8/2022 | |
3.1.30 | 1,330,686 | 10/11/2022 | |
3.1.29 | 1,837,856 | 9/13/2022 | |
3.1.28 | 1,052,256 | 8/9/2022 | |
3.1.27 | 1,041,939 | 7/12/2022 | |
3.1.26 | 816,096 | 6/14/2022 | |
3.1.25 | 1,337,093 | 5/10/2022 | |
3.1.24 | 909,798 | 4/11/2022 | |
3.1.23 | 1,733,508 | 3/8/2022 | |
3.1.22 | 5,643,517 | 12/14/2021 | |
3.1.21 | 3,839,399 | 11/7/2021 | |
3.1.20 | 2,437,786 | 10/11/2021 | |
3.1.19 | 2,851,133 | 9/14/2021 | |
3.1.18 | 6,219,189 | 8/10/2021 | |
3.1.17 | 2,517,317 | 7/13/2021 | |
3.1.16 | 3,812,369 | 6/8/2021 | |
3.1.15 | 3,926,634 | 5/11/2021 | |
3.1.14 | 4,903,397 | 4/6/2021 | |
3.1.13 | 6,045,980 | 3/9/2021 | |
3.1.12 | 4,048,141 | 2/9/2021 | |
3.1.11 | 6,936,640 | 1/12/2021 | |
3.1.10 | 13,154,575 | 11/9/2020 | |
3.1.9 | 17,872,384 | 10/13/2020 | |
3.1.8 | 37,746,749 | 9/8/2020 | |
3.1.7 | 17,689,952 | 8/11/2020 | |
3.1.6 | 19,050,381 | 7/14/2020 | |
3.1.5 | 18,588,171 | 6/9/2020 | |
3.1.4 | 21,814,168 | 5/12/2020 | |
3.1.3 | 33,748,905 | 3/24/2020 | |
3.1.2 | 16,322,433 | 2/18/2020 | |
3.1.1 | 26,374,608 | 1/14/2020 | |
3.1.0 | 46,987,600 | 12/3/2019 | |
3.1.0-preview3.19553.2 | 171,932 | 11/13/2019 | |
3.1.0-preview2.19525.4 | 33,548 | 11/1/2019 | |
3.1.0-preview1.19506.1 | 786,413 | 10/15/2019 | |
3.0.3 | 354,210 | 2/18/2020 | |
3.0.2 | 99,329 | 1/14/2020 | |
3.0.1 | 2,260,951 | 11/18/2019 | |
3.0.0 | 42,787,549 | 9/23/2019 | |
3.0.0-rc1.19456.10 | 47,867 | 9/16/2019 | |
3.0.0-preview9.19423.4 | 1,401,101 | 9/4/2019 | |
3.0.0-preview8.19405.4 | 435,112 | 8/13/2019 | |
3.0.0-preview7.19362.4 | 100,453 | 7/23/2019 | |
3.0.0-preview6.19304.6 | 187,381 | 6/12/2019 | |
3.0.0-preview5.19227.9 | 691,524 | 5/6/2019 | |
3.0.0-preview4.19216.2 | 23,608 | 4/18/2019 | |
3.0.0-preview3.19153.1 | 227,268 | 3/6/2019 | |
3.0.0-preview.19074.2 | 34,829 | 1/29/2019 | |
3.0.0-preview.18572.1 | 54,820 | 12/3/2018 | |
2.2.0 | 184,372,121 | 12/3/2018 | |
2.2.0-preview3-35497 | 246,892 | 10/17/2018 | |
2.2.0-preview2-35157 | 183,544 | 9/12/2018 | |
2.2.0-preview1-35029 | 109,866 | 8/22/2018 | |
2.1.23 | 53,681,591 | 10/13/2020 | |
2.1.2 | 36,752,429 | 8/21/2018 | |
2.1.1 | 54,028,927 | 6/18/2018 | |
2.1.0 | 81,880,234 | 5/29/2018 | |
2.1.0-rc1-final | 266,752 | 5/6/2018 | |
2.1.0-preview2-final | 262,320 | 4/10/2018 | |
2.1.0-preview1-final | 412,941 | 2/26/2018 | |
2.0.2 | 11,716,699 | 5/7/2018 | |
2.0.1 | 18,028,919 | 3/13/2018 | |
2.0.0 | 119,077,346 | 8/11/2017 | |
2.0.0-preview2-final | 140,707 | 6/28/2017 | |
2.0.0-preview1-final | 1,101,382 | 5/10/2017 | |
1.1.2 | 9,159,096 | 5/9/2017 | |
1.1.1 | 18,818,875 | 3/6/2017 | |
1.1.0 | 10,889,658 | 11/16/2016 | |
1.1.0-preview1-final | 72,386 | 10/24/2016 | |
1.0.2 | 4,658,840 | 3/6/2017 | |
1.0.1 | 632,729 | 12/12/2016 | |
1.0.0 | 336,207,685 | 6/27/2016 | |
1.0.0-rc2-final | 306,101 | 5/16/2016 | |
1.0.0-rc1-final | 519,453 | 11/18/2015 |