Microsoft.Extensions.Caching.Memory 9.0.11

About

Provides implementations for local and distributed in-memory cache. It stores and retrieves data in a fast and efficient way.

Key Features

  • A concrete implementation of the IMemoryCache interface, which represents a local in-memory cache that stores and retrieves data in a fast and efficient way
  • A distributed cache that supports higher scale-out than local cache
  • Expiration and eviction policies for its entries
  • Entry prioritization for when the cache size limit is exceeded and needs to be compacted by entry eviction
  • Track of cache statictics

How to Use

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)}");

Main Types

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

Additional Documentation

Microsoft.Extensions.Caching.Abstractions

Feedback & Contributing

Microsoft.Extensions.Caching.Memory is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.Extensions.Caching.Memory.

Packages 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
5,736
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
5,508
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
520
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
515
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
299
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
230
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
194
Microsoft.EntityFrameworkCore
Entity Framework Core is a lightweight and extensible version of the popular Entity Framework data access technology. Commonly Used Types: Microsoft.EntityFrameworkCore.DbContext Microsoft.EntityFrameworkCore.DbSet
133
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
93
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
89
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
85
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
84
Microsoft.EntityFrameworkCore
Entity Framework Core is a lightweight and extensible version of the popular Entity Framework data access technology. Commonly Used Types: Microsoft.EntityFrameworkCore.DbContext Microsoft.EntityFrameworkCore.DbSet
84
Microsoft.EntityFrameworkCore
Entity Framework Core is a lightweight and extensible version of the popular Entity Framework data access technology. Commonly Used Types: Microsoft.EntityFrameworkCore.DbContext Microsoft.EntityFrameworkCore.DbSet This package was built from the source code at https://github.com/aspnet/EntityFrameworkCore/tree/8e7402701ea1416b7fe55e1863ae65b3147c02c7
82
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
81
Microsoft.AspNetCore.Mvc
ASP.NET Core MVC is a web framework that gives you a powerful, patterns-based way to build dynamic websites and web APIs. ASP.NET Core MVC enables a clean separation of concerns and gives you full control over markup. This package was built from the source code at https://github.com/aspnet/Mvc/tree/a6199bbfbab05583f987bae322fb04566841aaea
80
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
79
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
78
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
78
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
77

https://go.microsoft.com/fwlink/?LinkID=799421

Version Downloads Last updated
10.0.0 7 11/13/2025
10.0.0-rc.2.25502.107 9 10/16/2025
10.0.0-rc.1.25451.107 9 09/11/2025
10.0.0-preview.7.25380.108 12 08/14/2025
10.0.0-preview.6.25358.103 15 07/17/2025
10.0.0-preview.5.25277.114 19 06/09/2025
10.0.0-preview.4.25258.110 26 05/16/2025
10.0.0-preview.3.25171.5 24 04/12/2025
10.0.0-preview.2.25163.2 25 03/23/2025
10.0.0-preview.1.25080.5 30 02/26/2025
9.0.11 6 11/13/2025
9.0.10 6 10/16/2025
9.0.9 13 09/11/2025
9.0.8 871 08/05/2025
9.0.7 879 07/10/2025
9.0.6 17 06/14/2025
9.0.5 21 05/17/2025
9.0.4 24 04/12/2025
9.0.3 31 03/17/2025
9.0.2 28 02/13/2025
9.0.1 26 01/19/2025
9.0.0 46 11/14/2024
9.0.0-rc.2.24473.5 39 10/18/2024
9.0.0-rc.1.24431.7 37 09/17/2024
9.0.0-preview.7.24405.7 42 08/14/2024
9.0.0-preview.6.24327.7 49 07/11/2024
9.0.0-preview.5.24306.7 42 06/11/2024
9.0.0-preview.4.24266.19 49 05/24/2024
9.0.0-preview.3.24172.9 54 04/13/2024
9.0.0-preview.2.24128.5 45 03/24/2024
9.0.0-preview.1.24080.9 52 03/06/2024
8.0.1 35 10/22/2024
8.0.0 5,735 11/15/2023
8.0.0-rc.2.23479.6 64 10/10/2023
8.0.0-rc.1.23419.4 53 09/14/2023
8.0.0-preview.7.23375.6 65 08/25/2023
8.0.0-preview.6.23329.7 62 07/11/2023
8.0.0-preview.5.23280.8 53 07/17/2023
8.0.0-preview.4.23259.5 60 06/30/2023
8.0.0-preview.3.23174.8 60 05/10/2023
8.0.0-preview.2.23128.3 525 04/03/2023
8.0.0-preview.1.23110.8 52 05/14/2023
7.0.0 542 12/02/2022
7.0.0-rc.2.22472.3 61 07/03/2023
7.0.0-rc.1.22426.10 73 07/06/2023
7.0.0-preview.7.22375.6 65 08/10/2022
7.0.0-preview.6.22324.4 65 07/12/2023
7.0.0-preview.5.22301.12 59 07/14/2023
7.0.0-preview.4.22229.4 67 11/24/2022
7.0.0-preview.3.22175.4 66 08/02/2022
7.0.0-preview.2.22152.2 61 07/14/2023
7.0.0-preview.1.22076.8 67 03/02/2022
6.0.3 39 11/13/2024
6.0.2 33 10/22/2024
6.0.2-mauipre.1.22102.15 58 09/25/2022
6.0.2-mauipre.1.22054.8 61 11/07/2022
6.0.1 74 02/10/2022
6.0.0 57 12/01/2021
6.0.0-rc.2.21480.5 65 07/17/2023
6.0.0-rc.1.21451.13 57 07/03/2023
6.0.0-preview.7.21377.19 64 07/02/2023
6.0.0-preview.6.21352.12 61 07/23/2022
6.0.0-preview.5.21301.5 65 07/03/2023
6.0.0-preview.4.21253.7 51 07/09/2023
6.0.0-preview.3.21201.4 58 11/15/2022
6.0.0-preview.2.21154.6 71 11/29/2022
6.0.0-preview.1.21102.12 57 07/10/2023
5.0.0 80 02/15/2021
5.0.0-rc.2.20475.5 58 07/09/2023
5.0.0-rc.1.20451.14 69 06/21/2023
5.0.0-preview.8.20407.11 67 07/11/2023
5.0.0-preview.7.20364.11 72 07/08/2023
5.0.0-preview.6.20305.6 53 07/09/2023
5.0.0-preview.5.20278.1 70 01/26/2023
5.0.0-preview.4.20251.6 73 07/09/2023
5.0.0-preview.3.20215.2 65 07/01/2023
5.0.0-preview.2.20160.3 82 11/14/2022
5.0.0-preview.1.20120.4 69 08/28/2022
3.1.32 60 05/12/2023
3.1.31 55 01/30/2023
3.1.30 50 07/02/2023
3.1.29 51 12/26/2022
3.1.28 69 11/07/2022
3.1.27 57 01/20/2023
3.1.26 77 07/21/2022
3.1.25 61 11/15/2022
3.1.24 60 11/06/2022
3.1.23 56 01/23/2023
3.1.22 50 11/15/2022
3.1.21 60 12/30/2022
3.1.20 64 11/11/2022
3.1.19 79 10/28/2022
3.1.18 60 11/08/2022
3.1.17 74 11/23/2022
3.1.16 54 07/10/2022
3.1.15 56 11/19/2022
3.1.14 52 01/23/2023
3.1.13 57 11/23/2022
3.1.12 53 01/18/2023
3.1.11 58 12/30/2022
3.1.10 52 11/12/2022
3.1.9 62 05/25/2023
3.1.8 51 11/24/2022
3.1.7 68 11/09/2020
3.1.6 70 11/14/2022
3.1.5 56 05/19/2023
3.1.4 51 12/19/2022
3.1.3 56 11/10/2022
3.1.2 59 12/15/2022
3.1.1 74 12/02/2022
3.1.0 55 11/05/2022
3.1.0-preview3.19553.2 56 06/07/2022
3.1.0-preview2.19525.4 53 09/28/2022
3.1.0-preview1.19506.1 55 09/26/2022
3.0.3 59 07/25/2022
3.0.2 51 01/22/2023
3.0.1 71 11/15/2022
3.0.0 58 11/20/2022
3.0.0-rc1.19456.10 65 09/28/2022
3.0.0-preview9.19423.4 56 10/03/2022
3.0.0-preview8.19405.4 64 07/09/2023
3.0.0-preview7.19362.4 62 07/09/2023
3.0.0-preview6.19304.6 65 07/12/2023
3.0.0-preview5.19227.9 54 11/18/2022
3.0.0-preview4.19216.2 56 12/30/2022
3.0.0-preview3.19153.1 63 12/05/2022
3.0.0-preview.19074.2 49 07/03/2023
3.0.0-preview.18572.1 66 07/09/2023
2.2.0 63 12/17/2022
2.2.0-preview3-35497 64 07/18/2022
2.2.0-preview2-35157 61 07/08/2023
2.2.0-preview1-35029 56 07/20/2022
2.1.23 61 10/05/2022
2.1.2 60 12/20/2021
2.1.1 63 06/07/2022
2.1.0 65 04/06/2023
2.1.0-rc1-final 53 02/01/2023
2.1.0-preview2-final 66 12/16/2022
2.1.0-preview1-final 55 10/30/2022
2.0.2 62 12/03/2022
2.0.1 80 01/07/2023
2.0.0 69 06/07/2022
2.0.0-preview2-final 49 05/23/2023
2.0.0-preview1-final 70 11/18/2022
1.1.2 75 10/28/2022
1.1.1 61 11/08/2022
1.1.0 51 04/21/2023
1.1.0-preview1-final 85 06/19/2022
1.0.2 69 09/15/2022
1.0.1 67 12/20/2021
1.0.0 60 06/11/2022
1.0.0-rc2-final 62 05/18/2023
1.0.0-rc1-final 71 06/30/2022