Microsoft.Extensions.Caching.Memory 10.0.1

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.AspNetCore.Mvc.Razor.Host
ASP.NET Core MVC design time hosting infrastructure for the Razor view engine.
177
Microsoft.AspNetCore.Mvc.TagHelpers
ASP.NET Core MVC default tag helpers. Contains tag helpers for anchor tags, HTML input elements, caching, scripts, links (for CSS), and more. This package was built from the source code at https://github.com/aspnet/Mvc/tree/a6199bbfbab05583f987bae322fb04566841aaea
161
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.
153
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
151
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
149
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.
147
Microsoft.AspNetCore.Mvc.TagHelpers
ASP.NET Core MVC default tag helpers. Contains tag helpers for anchor tags, HTML input elements, caching, scripts, links (for CSS), and more.
146
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
145
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.
142
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
141
Microsoft.AspNetCore.Mvc.Razor.Host
ASP.NET Core MVC design time hosting infrastructure for the Razor view engine.
140
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
140
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
138
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.
137
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
137
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
136
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
135
Microsoft.AspNetCore.Mvc.Razor
ASP.NET Core MVC Razor view engine for CSHTML files.
134
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.
134

Version Downloads Last updated
10.0.1 3 12/9/2025
10.0.0 28 11/13/2025
10.0.0-rc.2.25502.107 28 10/20/2025
10.0.0-rc.1.25451.107 43 9/15/2025
10.0.0-preview.7.25380.108 45 8/18/2025
10.0.0-preview.6.25358.103 51 7/18/2025
10.0.0-preview.5.25277.114 66 6/8/2025
10.0.0-preview.4.25258.110 56 5/15/2025
10.0.0-preview.3.25171.5 79 4/11/2025
10.0.0-preview.2.25163.2 62 3/18/2025
10.0.0-preview.1.25080.5 76 2/26/2025
9.0.11 24 11/13/2025
9.0.10 30 10/17/2025
9.0.9 43 9/11/2025
9.0.8 39 8/6/2025
9.0.7 46 7/11/2025
9.0.6 49 6/12/2025
9.0.5 72 5/16/2025
9.0.4 62 4/8/2025
9.0.3 60 3/17/2025
9.0.2 75 2/18/2025
9.0.1 92 1/21/2025
9.0.0 77 11/16/2024
9.0.0-rc.2.24473.5 71 10/13/2024
9.0.0-rc.1.24431.7 79 9/11/2024
9.0.0-preview.7.24405.7 93 8/13/2024
9.0.0-preview.6.24327.7 97 7/10/2024
9.0.0-preview.5.24306.7 86 6/14/2024
9.0.0-preview.4.24266.19 80 6/1/2024
9.0.0-preview.3.24172.9 86 4/17/2024
9.0.0-preview.2.24128.5 72 3/22/2024
9.0.0-preview.1.24080.9 88 2/23/2024
8.0.1 80 10/18/2024
8.0.0 108 11/16/2023
8.0.0-rc.2.23479.6 95 11/6/2023
8.0.0-rc.1.23419.4 89 9/17/2023
8.0.0-preview.7.23375.6 109 8/9/2023
8.0.0-preview.6.23329.7 99 7/31/2023
8.0.0-preview.5.23280.8 96 7/31/2023
8.0.0-preview.4.23259.5 88 5/20/2023
8.0.0-preview.3.23174.8 91 5/12/2023
8.0.0-preview.2.23128.3 96 5/28/2023
8.0.0-preview.1.23110.8 87 3/14/2023
7.0.0 102 12/3/2022
7.0.0-rc.2.22472.3 103 10/24/2022
7.0.0-rc.1.22426.10 91 9/16/2022
7.0.0-preview.7.22375.6 94 11/15/2022
7.0.0-preview.6.22324.4 89 9/28/2022
7.0.0-preview.5.22301.12 105 6/27/2022
7.0.0-preview.4.22229.4 97 6/29/2022
7.0.0-preview.3.22175.4 110 6/29/2022
7.0.0-preview.2.22152.2 112 6/29/2022
7.0.0-preview.1.22076.8 109 6/29/2022
6.0.3 84 11/16/2024
6.0.2 76 10/13/2024
6.0.2-mauipre.1.22102.15 95 6/29/2022
6.0.2-mauipre.1.22054.8 99 6/29/2022
6.0.1 96 6/29/2022
6.0.0 91 6/29/2022
6.0.0-rc.2.21480.5 87 6/29/2022
6.0.0-rc.1.21451.13 99 6/29/2022
6.0.0-preview.7.21377.19 138 6/29/2022
6.0.0-preview.6.21352.12 91 6/29/2022
6.0.0-preview.5.21301.5 92 6/29/2022
6.0.0-preview.4.21253.7 107 6/29/2022
6.0.0-preview.3.21201.4 106 6/29/2022
6.0.0-preview.2.21154.6 103 6/29/2022
6.0.0-preview.1.21102.12 96 6/29/2022
5.0.0 104 6/29/2022
5.0.0-rc.2.20475.5 100 6/29/2022
5.0.0-rc.1.20451.14 118 6/29/2022
5.0.0-preview.8.20407.11 97 6/29/2022
5.0.0-preview.7.20364.11 102 6/29/2022
5.0.0-preview.6.20305.6 108 6/29/2022
5.0.0-preview.5.20278.1 102 6/29/2022
5.0.0-preview.4.20251.6 99 6/29/2022
5.0.0-preview.3.20215.2 97 6/29/2022
5.0.0-preview.2.20160.3 119 6/29/2022
5.0.0-preview.1.20120.4 87 6/29/2022
3.1.32 113 1/11/2023
3.1.31 118 12/3/2022
3.1.30 112 10/15/2022
3.1.29 93 2/20/2023
3.1.28 127 9/11/2022
3.1.27 111 10/18/2022
3.1.26 95 6/29/2022
3.1.25 107 6/29/2022
3.1.24 115 6/29/2022
3.1.23 105 6/29/2022
3.1.22 99 6/29/2022
3.1.21 111 6/29/2022
3.1.20 81 6/29/2022
3.1.19 96 6/29/2022
3.1.18 98 6/29/2022
3.1.17 119 6/29/2022
3.1.16 91 6/29/2022
3.1.15 93 6/29/2022
3.1.14 103 6/29/2022
3.1.13 101 6/29/2022
3.1.12 89 6/29/2022
3.1.11 112 6/29/2022
3.1.10 95 6/29/2022
3.1.9 109 6/29/2022
3.1.8 95 6/29/2022
3.1.7 96 6/29/2022
3.1.6 95 6/29/2022
3.1.5 94 6/29/2022
3.1.4 99 6/29/2022
3.1.3 97 6/29/2022
3.1.2 91 6/29/2022
3.1.1 107 6/29/2022
3.1.0 93 6/29/2022
3.1.0-preview3.19553.2 89 6/29/2022
3.1.0-preview2.19525.4 99 6/29/2022
3.1.0-preview1.19506.1 105 6/29/2022
3.0.3 96 6/29/2022
3.0.2 95 6/29/2022
3.0.1 107 6/29/2022
3.0.0 105 6/29/2022
3.0.0-rc1.19456.10 102 6/29/2022
3.0.0-preview9.19423.4 108 6/29/2022
3.0.0-preview8.19405.4 104 6/29/2022
3.0.0-preview7.19362.4 119 6/29/2022
3.0.0-preview6.19304.6 104 6/29/2022
3.0.0-preview5.19227.9 100 6/29/2022
3.0.0-preview4.19216.2 89 6/29/2022
3.0.0-preview3.19153.1 103 6/29/2022
3.0.0-preview.19074.2 99 6/29/2022
3.0.0-preview.18572.1 102 6/29/2022
2.2.0 101 6/29/2022
2.2.0-preview3-35497 106 6/29/2022
2.2.0-preview2-35157 111 6/29/2022
2.2.0-preview1-35029 96 6/29/2022
2.1.23 96 6/29/2022
2.1.2 94 6/29/2022
2.1.1 110 6/29/2022
2.1.0 110 6/29/2022
2.1.0-rc1-final 100 6/29/2022
2.1.0-preview2-final 105 6/29/2022
2.1.0-preview1-final 102 6/29/2022
2.0.2 97 6/29/2022
2.0.1 104 6/29/2022
2.0.0 96 6/29/2022
2.0.0-preview2-final 94 6/29/2022
2.0.0-preview1-final 90 6/29/2022
1.1.2 93 6/29/2022
1.1.1 105 6/29/2022
1.1.0 106 6/29/2022
1.1.0-preview1-final 93 6/29/2022
1.0.2 92 6/29/2022
1.0.1 115 6/29/2022
1.0.0 97 6/29/2022
1.0.0-rc2-final 99 6/29/2022
1.0.0-rc1-final 112 6/29/2022