Microsoft.Extensions.Caching.Memory 9.0.2

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
4,913
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
4,682
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
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
294
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
224
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
187
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
129
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 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
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
76
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
76
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
74
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
74
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
72
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
71
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
70
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
70
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
70

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

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