diff --git a/docs/core/compatibility/7.0.md b/docs/core/compatibility/7.0.md index 8785d25d0ba4a..7a190bf2bf232 100644 --- a/docs/core/compatibility/7.0.md +++ b/docs/core/compatibility/7.0.md @@ -47,6 +47,7 @@ If you're migrating an app to .NET 7, the breaking changes listed here might aff | [Library support for older frameworks](core-libraries/7.0/old-framework-support.md) | ❌ | ❌ | Preview 1 | | [Maximum precision for numeric format strings](core-libraries/7.0/max-precision-numeric-format-strings.md) | ❌ | ✔️ | RC 1 | | [SerializationFormat.Binary is obsolete](core-libraries/7.0/serializationformat-binary.md) | ❌ | ❌ | Preview 2 | +| [Tracking linked cache entries](core-libraries/7.0/memorycache-tracking.md) | ❌ | ✔️ | Preview 1 | | [Validate CompressionLevel for BrotliStream](core-libraries/7.0/compressionlevel-validation.md) | ❌ | ✔️ | Preview 1 | ## Cryptography diff --git a/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md b/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md new file mode 100644 index 0000000000000..21c56199286fa --- /dev/null +++ b/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md @@ -0,0 +1,61 @@ +--- +title: "Breaking change: Tracking linked cache entries" +description: Learn about the .NET 7 breaking change in .NET where MemoryCache no longer tracks linked cache entries by default. +ms.date: 10/13/2022 +--- +# Tracking linked cache entries + + tracks linked cache entries so that options are propagated. In the following example, the `expirationToken` added for `child` is also applied to `parent`: + +```csharp +using (var parent = cache.CreateEntry(key)) +{ + parent.SetValue(obj); + + using (var child = cache.CreateEntry(key1)) + { + child.SetValue(obj); + child.AddExpirationToken(expirationToken); + } +} +``` + +For performance reasons, .NET 7 no longer tracks linked cache entries by default. However, you can enable tracking using a new option. + +## Version introduced + +.NET 7 Preview 1 + +## Previous behavior + +Prior to .NET 7, tracked linked cache entries to allow for options to be propagated. The tracking could not be disabled. + +## New behavior + +Starting in .NET 7, does not track linked cache entries, by default. The option was added so you can control whether linked cache entries are tracked or not. + +## Type of breaking change + +This change can affect [binary compatibility](../../categories.md#binary-compatibility). + +## Reason for change + +This change was introduced to improve performance. Tracking internally uses , which is expensive and adds non-trivial overhead. + +## Recommended action + +If you want to continue tracking linked cache entries so options can be propagated, set to `true`. + +```csharp +var options = new MemoryCacheOptions +{ + TrackLinkedCacheEntries = true +}; + +var cache = new MemoryCache(options); +``` + +## Affected APIs + +- +- diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index 86f52da79d290..be94e37a2c37e 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -75,6 +75,8 @@ items: href: core-libraries/7.0/reflection-invoke-exceptions.md - name: SerializationFormat.Binary is obsolete href: core-libraries/7.0/serializationformat-binary.md + - name: Tracking linked cache entries + href: core-libraries/7.0/memorycache-tracking.md - name: Validate CompressionLevel for BrotliStream href: core-libraries/7.0/compressionlevel-validation.md - name: Cryptography @@ -849,6 +851,8 @@ items: href: core-libraries/7.0/reflection-invoke-exceptions.md - name: SerializationFormat.Binary is obsolete href: core-libraries/7.0/serializationformat-binary.md + - name: Tracking linked cache entries + href: core-libraries/7.0/memorycache-tracking.md - name: Validate CompressionLevel for BrotliStream href: core-libraries/7.0/compressionlevel-validation.md - name: .NET 6