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,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
3,988
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
512
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
504
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
288
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
215
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
182
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
123
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
74
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
71
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
70
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
69
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
68
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
67
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
67
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
65
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
65
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.
63

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

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