Microsoft.Extensions.Caching.Memory 9.0.0-preview.2.24128.5

Prefix Reserved
Details
Advisory: https://github.com/advisories/GHSA-qj66-m88j-hmgj Severity: high
This is a prerelease version of Microsoft.Extensions.Caching.Memory.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Microsoft.Extensions.Caching.Memory --version 9.0.0-preview.2.24128.5                
NuGet\Install-Package Microsoft.Extensions.Caching.Memory -Version 9.0.0-preview.2.24128.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-preview.2.24128.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.Extensions.Caching.Memory --version 9.0.0-preview.2.24128.5                
#r "nuget: Microsoft.Extensions.Caching.Memory, 9.0.0-preview.2.24128.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microsoft.Extensions.Caching.Memory as a Cake Addin
#addin nuget:?package=Microsoft.Extensions.Caching.Memory&version=9.0.0-preview.2.24128.5&prerelease

// Install Microsoft.Extensions.Caching.Memory as a Cake Tool
#tool nuget:?package=Microsoft.Extensions.Caching.Memory&version=9.0.0-preview.2.24128.5&prerelease                

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2.5K)

Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Caching.Memory:

Package 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

Microsoft.EntityFrameworkCore.Relational

Shared Entity Framework Core components for relational database providers.

Microsoft.Data.SqlClient

The current data provider for SQL Server and Azure SQL databases. This has replaced System.Data.SqlClient. These classes provide access to SQL and encapsulate database-specific protocols, including tabular data stream (TDS). Commonly Used Types: Microsoft.Data.SqlClient.SqlConnection Microsoft.Data.SqlClient.SqlException Microsoft.Data.SqlClient.SqlParameter Microsoft.Data.SqlClient.SqlDataReader Microsoft.Data.SqlClient.SqlCommand Microsoft.Data.SqlClient.SqlTransaction Microsoft.Data.SqlClient.SqlParameterCollection Microsoft.Data.SqlClient.SqlClientFactory When using NuGet 3.x this package requires at least version 3.4.

Microsoft.EntityFrameworkCore.SqlServer

Microsoft SQL Server database provider for Entity Framework Core.

Microsoft.EntityFrameworkCore.Design

Shared design-time components for Entity Framework Core tools.

GitHub repositories (272)

Showing the top 5 popular GitHub repositories that depend on Microsoft.Extensions.Caching.Memory:

Repository Stars
jellyfin/jellyfin
The Free Software Media System
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
App-vNext/Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
Version Downloads Last updated
9.0.0-rc.2.24473.5 97,965 10/8/2024
9.0.0-rc.1.24431.7 88,285 9/10/2024 9.0.0-rc.1.24431.7 has at least one vulnerability with high severity.
9.0.0-preview.7.24405.7 70,355 8/13/2024 9.0.0-preview.7.24405.7 has at least one vulnerability with high severity.
9.0.0-preview.6.24327.7 124,457 7/9/2024 9.0.0-preview.6.24327.7 has at least one vulnerability with high severity.
9.0.0-preview.5.24306.7 59,402 6/11/2024 9.0.0-preview.5.24306.7 has at least one vulnerability with high severity.
9.0.0-preview.4.24266.19 57,650 5/21/2024 9.0.0-preview.4.24266.19 has at least one vulnerability with high severity.
9.0.0-preview.3.24172.9 157,994 4/11/2024 9.0.0-preview.3.24172.9 has at least one vulnerability with high severity.
9.0.0-preview.2.24128.5 73,876 3/12/2024 9.0.0-preview.2.24128.5 has at least one vulnerability with high severity.
9.0.0-preview.1.24080.9 80,985 2/13/2024 9.0.0-preview.1.24080.9 has at least one vulnerability with high severity.
8.0.1 5,770,735 10/8/2024
8.0.0 98,505,485 11/14/2023 8.0.0 has at least one vulnerability with high severity.
8.0.0-rc.2.23479.6 1,127,908 10/10/2023 8.0.0-rc.2.23479.6 has at least one vulnerability with high severity.
8.0.0-rc.1.23419.4 293,271 9/12/2023 8.0.0-rc.1.23419.4 has at least one vulnerability with high severity.
8.0.0-preview.7.23375.6 315,858 8/8/2023 8.0.0-preview.7.23375.6 has at least one vulnerability with high severity.
8.0.0-preview.6.23329.7 166,416 7/11/2023 8.0.0-preview.6.23329.7 has at least one vulnerability with high severity.
8.0.0-preview.5.23280.8 131,666 6/13/2023 8.0.0-preview.5.23280.8 has at least one vulnerability with high severity.
8.0.0-preview.4.23259.5 130,757 5/16/2023 8.0.0-preview.4.23259.5 has at least one vulnerability with high severity.
8.0.0-preview.3.23174.8 192,130 4/11/2023 8.0.0-preview.3.23174.8 has at least one vulnerability with high severity.
8.0.0-preview.2.23128.3 199,870 3/14/2023 8.0.0-preview.2.23128.3 has at least one vulnerability with high severity.
8.0.0-preview.1.23110.8 136,263 2/21/2023 8.0.0-preview.1.23110.8 has at least one vulnerability with high severity.
7.0.0 130,819,942 11/7/2022
7.0.0-rc.2.22472.3 234,868 10/11/2022
7.0.0-rc.1.22426.10 238,865 9/14/2022
7.0.0-preview.7.22375.6 107,234 8/9/2022
7.0.0-preview.6.22324.4 76,593 7/12/2022
7.0.0-preview.5.22301.12 66,935 6/14/2022
7.0.0-preview.4.22229.4 79,129 5/10/2022
7.0.0-preview.3.22175.4 78,025 4/13/2022
7.0.0-preview.2.22152.2 86,430 3/14/2022
7.0.0-preview.1.22076.8 71,173 2/17/2022
6.0.2 365,061 10/8/2024
6.0.1 218,463,703 2/8/2022 6.0.1 has at least one vulnerability with high severity.
6.0.0 107,262,860 11/8/2021 6.0.0 has at least one vulnerability with high severity.
6.0.0-rc.2.21480.5 481,443 10/12/2021 6.0.0-rc.2.21480.5 has at least one vulnerability with high severity.
6.0.0-rc.1.21451.13 240,234 9/14/2021 6.0.0-rc.1.21451.13 has at least one vulnerability with high severity.
6.0.0-preview.7.21377.19 95,378 8/10/2021 6.0.0-preview.7.21377.19 has at least one vulnerability with high severity.
6.0.0-preview.6.21352.12 48,767 7/14/2021 6.0.0-preview.6.21352.12 has at least one vulnerability with high severity.
6.0.0-preview.5.21301.5 185,052 6/15/2021 6.0.0-preview.5.21301.5 has at least one vulnerability with high severity.
6.0.0-preview.4.21253.7 85,996 5/24/2021 6.0.0-preview.4.21253.7 has at least one vulnerability with high severity.
6.0.0-preview.3.21201.4 98,721 4/8/2021 6.0.0-preview.3.21201.4 has at least one vulnerability with high severity.
6.0.0-preview.2.21154.6 73,967 3/11/2021 6.0.0-preview.2.21154.6 is deprecated because it is no longer maintained; 6.0.0-preview.2.21154.6 has at least one vulnerability with high severity.
6.0.0-preview.1.21102.12 365,507 2/12/2021 6.0.0-preview.1.21102.12 is deprecated because it is no longer maintained; 6.0.0-preview.1.21102.12 has at least one vulnerability with high severity.
5.0.0 174,992,225 11/9/2020 5.0.0 is deprecated because it is no longer maintained.
5.0.0-rc.2.20475.5 380,773 10/13/2020 5.0.0-rc.2.20475.5 is deprecated because it is no longer maintained.
5.0.0-rc.1.20451.14 324,079 9/14/2020 5.0.0-rc.1.20451.14 is deprecated because it is no longer maintained.
5.0.0-preview.8.20407.11 202,123 8/25/2020 5.0.0-preview.8.20407.11 is deprecated because it is no longer maintained.
5.0.0-preview.7.20364.11 117,219 7/21/2020 5.0.0-preview.7.20364.11 is deprecated because it is no longer maintained.
5.0.0-preview.6.20305.6 58,819 6/25/2020 5.0.0-preview.6.20305.6 is deprecated because it is no longer maintained.
5.0.0-preview.5.20278.1 6,387 6/10/2020 5.0.0-preview.5.20278.1 is deprecated because it is no longer maintained.
5.0.0-preview.4.20251.6 202,033 5/18/2020 5.0.0-preview.4.20251.6 is deprecated because it is no longer maintained.
5.0.0-preview.3.20215.2 116,985 4/23/2020 5.0.0-preview.3.20215.2 is deprecated because it is no longer maintained.
5.0.0-preview.2.20160.3 111,849 4/2/2020 5.0.0-preview.2.20160.3 is deprecated because it is no longer maintained.
5.0.0-preview.1.20120.4 62,157 3/16/2020 5.0.0-preview.1.20120.4 is deprecated because it is no longer maintained.
3.1.32 5,232,734 12/13/2022
3.1.31 1,010,979 11/8/2022
3.1.30 1,039,596 10/11/2022
3.1.29 1,328,734 9/13/2022
3.1.28 872,387 8/9/2022
3.1.27 909,444 7/12/2022
3.1.26 736,222 6/14/2022
3.1.25 1,185,688 5/10/2022
3.1.24 809,968 4/11/2022
3.1.23 1,534,640 3/8/2022
3.1.22 4,677,019 12/14/2021
3.1.21 3,468,305 11/7/2021
3.1.20 1,983,933 10/11/2021
3.1.19 2,654,043 9/14/2021
3.1.18 5,509,228 8/10/2021
3.1.17 2,333,388 7/13/2021
3.1.16 3,445,338 6/8/2021
3.1.15 3,526,300 5/11/2021
3.1.14 4,464,754 4/6/2021
3.1.13 5,473,214 3/9/2021
3.1.12 3,818,718 2/9/2021
3.1.11 6,448,056 1/12/2021
3.1.10 12,288,253 11/9/2020
3.1.9 16,694,716 10/13/2020
3.1.8 31,658,758 9/8/2020
3.1.7 16,341,079 8/11/2020
3.1.6 17,475,545 7/14/2020
3.1.5 17,507,742 6/9/2020
3.1.4 20,464,879 5/12/2020
3.1.3 31,353,078 3/24/2020
3.1.2 15,463,960 2/18/2020
3.1.1 24,393,727 1/14/2020
3.1.0 41,413,881 12/3/2019
3.1.0-preview3.19553.2 164,843 11/13/2019 3.1.0-preview3.19553.2 is deprecated because it is no longer maintained.
3.1.0-preview2.19525.4 32,210 11/1/2019 3.1.0-preview2.19525.4 is deprecated because it is no longer maintained.
3.1.0-preview1.19506.1 735,678 10/15/2019 3.1.0-preview1.19506.1 is deprecated because it is no longer maintained.
3.0.3 318,325 2/18/2020 3.0.3 is deprecated because it is no longer maintained.
3.0.2 95,328 1/14/2020 3.0.2 is deprecated because it is no longer maintained.
3.0.1 2,162,117 11/18/2019 3.0.1 is deprecated because it is no longer maintained.
3.0.0 37,180,191 9/23/2019 3.0.0 is deprecated because it is no longer maintained.
3.0.0-rc1.19456.10 46,667 9/16/2019 3.0.0-rc1.19456.10 is deprecated because it is no longer maintained.
3.0.0-preview9.19423.4 1,356,856 9/4/2019 3.0.0-preview9.19423.4 is deprecated because it is no longer maintained.
3.0.0-preview8.19405.4 406,375 8/13/2019 3.0.0-preview8.19405.4 is deprecated because it is no longer maintained.
3.0.0-preview7.19362.4 92,617 7/23/2019 3.0.0-preview7.19362.4 is deprecated because it is no longer maintained.
3.0.0-preview6.19304.6 177,536 6/12/2019 3.0.0-preview6.19304.6 is deprecated because it is no longer maintained.
3.0.0-preview5.19227.9 647,786 5/6/2019 3.0.0-preview5.19227.9 is deprecated because it is no longer maintained.
3.0.0-preview4.19216.2 22,856 4/18/2019 3.0.0-preview4.19216.2 is deprecated because it is no longer maintained.
3.0.0-preview3.19153.1 216,586 3/6/2019 3.0.0-preview3.19153.1 is deprecated because it is no longer maintained.
3.0.0-preview.19074.2 32,430 1/29/2019 3.0.0-preview.19074.2 is deprecated because it is no longer maintained.
3.0.0-preview.18572.1 52,828 12/3/2018 3.0.0-preview.18572.1 is deprecated because it is no longer maintained.
2.2.0 155,230,367 12/3/2018 2.2.0 is deprecated because it is no longer maintained.
2.2.0-preview3-35497 242,745 10/17/2018 2.2.0-preview3-35497 is deprecated because it is no longer maintained.
2.2.0-preview2-35157 173,116 9/12/2018 2.2.0-preview2-35157 is deprecated because it is no longer maintained.
2.2.0-preview1-35029 101,863 8/22/2018 2.2.0-preview1-35029 is deprecated because it is no longer maintained.
2.1.23 23,933,690 10/13/2020
2.1.2 33,100,741 8/21/2018
2.1.1 47,902,818 6/18/2018
2.1.0 67,867,576 5/29/2018
2.1.0-rc1-final 256,678 5/6/2018 2.1.0-rc1-final is deprecated because it is no longer maintained.
2.1.0-preview2-final 249,186 4/10/2018 2.1.0-preview2-final is deprecated because it is no longer maintained.
2.1.0-preview1-final 398,886 2/26/2018 2.1.0-preview1-final is deprecated because it is no longer maintained.
2.0.2 10,897,950 5/7/2018 2.0.2 is deprecated because it is no longer maintained.
2.0.1 17,124,182 3/13/2018 2.0.1 is deprecated because it is no longer maintained.
2.0.0 107,366,438 8/11/2017 2.0.0 is deprecated because it is no longer maintained.
2.0.0-preview2-final 134,324 6/28/2017 2.0.0-preview2-final is deprecated because it is no longer maintained.
2.0.0-preview1-final 1,063,384 5/10/2017 2.0.0-preview1-final is deprecated because it is no longer maintained.
1.1.2 8,205,414 5/9/2017 1.1.2 is deprecated because it is no longer maintained.
1.1.1 17,111,355 3/6/2017 1.1.1 is deprecated because it is no longer maintained.
1.1.0 9,306,224 11/16/2016 1.1.0 is deprecated because it is no longer maintained.
1.1.0-preview1-final 70,349 10/24/2016 1.1.0-preview1-final is deprecated because it is no longer maintained.
1.0.2 4,212,681 3/6/2017 1.0.2 is deprecated because it is no longer maintained.
1.0.1 625,972 12/12/2016 1.0.1 is deprecated because it is no longer maintained.
1.0.0 247,735,240 6/27/2016 1.0.0 is deprecated because it is no longer maintained.
1.0.0-rc2-final 283,383 5/16/2016 1.0.0-rc2-final is deprecated because it is no longer maintained.
1.0.0-rc1-final 510,789 11/18/2015 1.0.0-rc1-final is deprecated because it is no longer maintained.