Microsoft.Extensions.Caching.Memory 9.0.10

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,213
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,984
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
519
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
511
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
298
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
226
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
189
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
130
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
86
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
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
80
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
79
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
78
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
76
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
75
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
75
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
74
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
74
Z.Expressions.Eval
C# Eval Expression is an Eval function. You can Evaluate, Compile and Execute C# code at runtime. Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
73

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

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