[Breaking change]: Extend MemoryCacheOptions with TrackLinkedCacheEntries #31739
Closed
1 of 2 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 7
Work items for the .NET 7 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
source incompatible
Source code may encounter a breaking change in behavior when targeting the new version.
Description
Background and Motivation
MemoryCache
by default tracks linked cache entries to allow for propagating options.In the following example, the
expirationToken
added forchild
is also applied toparent
:Tracking internally uses
AsyncLocal<T>
, which is expensive and adds non-trivial overhead. The cost of using it has popped out in the performance reports that we have received from our customers (#45436).Before this feature this behavior could not be disabled.
New API
Here we extend the existing
MemoryCacheOptions
with a flag that disables this behaviour.namespace Microsoft.Extensions.Caching.Memory { public class MemoryCacheOptions { + public bool TrackLinkedCacheEntries { get ; set; } } }
Usage Examples
Risks
We have changed the defaults, it's now disabled by default.
Version
.NET 7 Preview 1
Previous behavior
MemoryCache by default tracks linked cache entries to allow for propagating options.
New behavior
Using
MemoryCacheOptions.TrackLinkedCacheEntries
this behavior can be configured properly.Type of breaking change
Reason for change
Performance improvement
Recommended action
Refer to usage sample.
Feature area
C#, Core .NET libraries, Extensions
Affected APIs
The text was updated successfully, but these errors were encountered: