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
3,946
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,702
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
505
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
497
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
285
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
209
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
173
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
115
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.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
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
64
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
63
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
62
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
60
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
60
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
59
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
56
IdentityServer4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
56
Askmethat.Aspnet.JsonLocalizer
Json Localizer library for .NetStandard and .NetCore Asp.net projects
55
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
55

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

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