From d5fd620cf2dfaa3816a66fac5a2b1bb74c0f7415 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 13 Oct 2022 14:42:45 -0700 Subject: [PATCH 1/2] memorycache breaking change --- docs/core/compatibility/7.0.md | 1 + .../7.0/memorycache-tracking.md | 61 +++++++++++++++++++ docs/core/compatibility/toc.yml | 4 ++ 3 files changed, 66 insertions(+) create mode 100644 docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md 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..5b4c3ca17c2ea --- /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 to 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 From bdd1847b47efdcdd889a5c0552c86d8a3c79c9e5 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 17 Oct 2022 09:06:27 -0700 Subject: [PATCH 2/2] Update docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md Co-authored-by: Cam Soper --- .../compatibility/core-libraries/7.0/memorycache-tracking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md b/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md index 5b4c3ca17c2ea..21c56199286fa 100644 --- a/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md +++ b/docs/core/compatibility/core-libraries/7.0/memorycache-tracking.md @@ -5,7 +5,7 @@ ms.date: 10/13/2022 --- # Tracking linked cache entries - tracks linked cache entries to that options are propagated. In the following example, the `expirationToken` added for `child` is also applied to `parent`: + 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))