Microsoft.Extensions.Caching.Memory 11.0.0

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
1,076
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
671
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
583
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
470
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
447
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
200
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
95
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
92
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
58
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
56
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
53
Z.Expressions.Eval
C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. * FREE trial & PRO version
51
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.
46
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
46
RulesEngine
Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.
44
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
43
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
42
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.
42
Z.Expressions.Eval
Evaluate, Compile and Execute C# code at runtime. Support: Dynamic LINQ, Extension Method, Expando Object, and more! Online Example: https://dotnetfiddle.net/COq6FC Include free and prime features.
41

Version Downloads Last updated
11.0.0 2 11/13/2026
11.0.0-rc.3.26522.148 3 10/28/2026
11.0.0-rc.2.26504.105 3 10/19/2026
11.0.0-rc.1.26425.128 5 09/11/2026
11.0.0-preview.7.26381.103 16 08/11/2026
11.0.0-preview.6.26359.118 13 07/15/2026
11.0.0-preview.5.26302.115 16 06/20/2026
11.0.0-preview.4.26230.115 18 05/14/2026
11.0.0-preview.3.26207.106 13 06/24/2026
11.0.0-preview.2.26159.112 16 03/21/2026
11.0.0-preview.1.26104.118 16 06/22/2026
10.0.15 1 11/14/2026
10.0.14 3 10/29/2026
10.0.13 1 10/21/2026
10.0.12 4 09/11/2026
10.0.11 12 08/11/2026
10.0.10 8 07/15/2026
10.0.9 12 06/23/2026
10.0.8 15 05/14/2026
10.0.7 11 04/28/2026
10.0.6 16 04/28/2026
10.0.5 17 03/21/2026
10.0.4 18 03/21/2026
10.0.3 10 02/21/2026
10.0.2 14 01/23/2026
10.0.1 19 12/23/2025
10.0.0 17 11/18/2025
10.0.0-rc.2.25502.107 17 10/22/2025
10.0.0-rc.1.25451.107 21 09/17/2025
10.0.0-preview.7.25380.108 14 08/28/2025
10.0.0-preview.6.25358.103 19 07/17/2025
10.0.0-preview.5.25277.114 19 06/16/2025
10.0.0-preview.4.25258.110 13 05/19/2025
10.0.0-preview.3.25171.5 14 04/18/2025
10.0.0-preview.2.25163.2 16 04/08/2025
10.0.0-preview.1.25080.5 17 03/16/2025
9.0.23 2 11/14/2026
9.0.22 2 11/09/2026
9.0.21 2 11/14/2026
9.0.20 4 09/14/2026
9.0.19 21 08/11/2026
9.0.18 13 07/16/2026
9.0.17 17 07/07/2026
9.0.16 13 06/24/2026
9.0.15 13 06/29/2026
9.0.14 9 07/09/2026
9.0.13 16 06/29/2026
9.0.12 9 07/07/2026
9.0.11 10 06/23/2026
9.0.10 13 06/23/2026
9.0.9 18 06/23/2026
9.0.8 15 06/23/2026
9.0.7 12 06/23/2026
9.0.6 17 06/23/2026
9.0.5 15 06/09/2025
9.0.4 16 04/13/2025
9.0.3 19 03/14/2025
9.0.2 20 02/17/2025
9.0.1 15 01/29/2025
9.0.0 23 12/17/2024
9.0.0-rc.2.24473.5 20 10/16/2024
9.0.0-rc.1.24431.7 18 09/21/2024
9.0.0-preview.7.24405.7 21 08/26/2024
9.0.0-preview.6.24327.7 19 07/21/2024
9.0.0-preview.5.24306.7 18 06/15/2024
9.0.0-preview.4.24266.19 24 09/19/2024
9.0.0-preview.3.24172.9 14 06/22/2026
9.0.0-preview.2.24128.5 12 06/22/2026
9.0.0-preview.1.24080.9 17 06/23/2026
8.0.1 20 11/05/2024
8.0.0 37 12/15/2023
8.0.0-rc.2.23479.6 16 12/01/2024
8.0.0-rc.1.23419.4 13 02/19/2024
8.0.0-preview.7.23375.6 16 06/22/2026
8.0.0-preview.6.23329.7 13 12/16/2024
8.0.0-preview.5.23280.8 17 06/23/2024
8.0.0-preview.4.23259.5 18 06/22/2026
8.0.0-preview.3.23174.8 18 12/15/2023
8.0.0-preview.2.23128.3 18 03/31/2025
8.0.0-preview.1.23110.8 16 12/26/2023
7.0.0 55 01/03/2023
7.0.0-rc.2.22472.3 14 08/13/2024
7.0.0-rc.1.22426.10 14 11/17/2025
7.0.0-preview.7.22375.6 12 07/15/2024
7.0.0-preview.6.22324.4 14 04/01/2025
7.0.0-preview.5.22301.12 17 03/15/2024
7.0.0-preview.4.22229.4 14 07/22/2024
7.0.0-preview.3.22175.4 20 10/02/2024
7.0.0-preview.2.22152.2 19 05/02/2025
7.0.0-preview.1.22076.8 15 05/23/2024
6.0.3 10 06/23/2026
6.0.2 16 06/20/2026
6.0.2-mauipre.1.22102.15 14 02/26/2025
6.0.2-mauipre.1.22054.8 15 05/21/2024
6.0.1 29 03/02/2022
6.0.0 14 03/10/2022
6.0.0-rc.2.21480.5 14 10/03/2024
6.0.0-rc.1.21451.13 17 11/12/2024
6.0.0-preview.7.21377.19 17 11/01/2024
6.0.0-preview.6.21352.12 15 01/20/2025
6.0.0-preview.5.21301.5 11 12/12/2023
6.0.0-preview.4.21253.7 15 03/30/2024
6.0.0-preview.3.21201.4 18 08/03/2024
6.0.0-preview.2.21154.6 18 08/10/2024
6.0.0-preview.1.21102.12 14 07/07/2024
5.0.0 905 02/16/2021
5.0.0-rc.2.20475.5 20 12/15/2023
5.0.0-rc.1.20451.14 13 01/06/2024
5.0.0-preview.8.20407.11 13 06/06/2024
5.0.0-preview.7.20364.11 12 11/20/2024
5.0.0-preview.6.20305.6 20 01/11/2024
5.0.0-preview.5.20278.1 14 07/24/2024
5.0.0-preview.4.20251.6 11 05/26/2025
5.0.0-preview.3.20215.2 18 06/24/2024
5.0.0-preview.2.20160.3 20 10/04/2024
5.0.0-preview.1.20120.4 16 08/05/2024
3.1.32 16 10/05/2024
3.1.31 20 02/13/2024
3.1.30 18 01/02/2024
3.1.29 16 09/02/2025
3.1.28 15 10/06/2024
3.1.27 13 10/06/2024
3.1.26 21 07/31/2024
3.1.25 17 12/18/2023
3.1.24 19 03/29/2024
3.1.23 14 02/12/2025
3.1.22 16 04/13/2024
3.1.21 15 02/21/2022
3.1.20 12 01/07/2024
3.1.19 17 05/30/2024
3.1.18 22 01/21/2024
3.1.17 15 04/05/2025
3.1.16 15 12/26/2023
3.1.15 22 12/27/2023
3.1.14 13 01/15/2024
3.1.13 14 06/23/2026
3.1.12 17 01/25/2024
3.1.11 14 10/05/2024
3.1.10 19 12/27/2023
3.1.9 16 01/08/2024
3.1.8 13 10/07/2024
3.1.7 17 05/14/2024
3.1.6 17 06/25/2024
3.1.5 18 09/30/2021
3.1.4 17 06/06/2024
3.1.3 23 03/06/2021
3.1.2 25 03/08/2021
3.1.1 15 12/21/2023
3.1.0 96 02/16/2021
3.1.0-preview3.19553.2 16 12/23/2023
3.1.0-preview2.19525.4 14 07/04/2026
3.1.0-preview1.19506.1 26 04/27/2025
3.0.3 14 04/28/2024
3.0.2 19 05/06/2024
3.0.1 15 09/18/2024
3.0.0 17 01/15/2025
3.0.0-rc1.19456.10 15 02/14/2024
3.0.0-preview9.19423.4 13 04/17/2025
3.0.0-preview8.19405.4 13 10/15/2024
3.0.0-preview7.19362.4 17 08/22/2024
3.0.0-preview6.19304.6 16 04/05/2025
3.0.0-preview5.19227.9 15 12/15/2023
3.0.0-preview4.19216.2 17 04/06/2025
3.0.0-preview3.19153.1 10 02/25/2024
3.0.0-preview.19074.2 14 03/16/2024
3.0.0-preview.18572.1 16 01/04/2024
2.2.0 19 04/17/2022
2.2.0-preview3-35497 10 10/07/2024
2.2.0-preview2-35157 14 10/08/2024
2.2.0-preview1-35029 17 12/31/2023
2.1.23 13 01/01/2024
2.1.2 18 12/29/2023
2.1.1 13 09/03/2021
2.1.0 21 09/03/2021
2.1.0-rc1-final 17 01/10/2024
2.1.0-preview2-final 27 10/03/2024
2.1.0-preview1-final 18 12/31/2024
2.0.2 16 04/18/2024
2.0.1 13 12/30/2023
2.0.0 556 12/12/2023
2.0.0-preview2-final 13 03/11/2024
2.0.0-preview1-final 13 12/03/2024
1.1.2 12 03/16/2024
1.1.1 10 06/23/2026
1.1.0 24 12/21/2023
1.1.0-preview1-final 11 06/10/2024
1.0.2 20 01/04/2024
1.0.1 20 12/17/2023
1.0.0 22 06/30/2024
1.0.0-rc2-final 21 12/12/2023
1.0.0-rc1-final 18 03/16/2024