-
Notifications
You must be signed in to change notification settings - Fork 217
Remove Gen2 GC based trigger for compacting memory cache #221 #265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,11 @@ public interface IMemoryCache : IDisposable | |
/// </summary> | ||
/// <param name="key">An object identifying the entry.</param> | ||
void Remove(object key); | ||
|
||
/// <summary> | ||
/// Attempt to remove the given percentage of the total entries in the cache. | ||
/// </summary> | ||
/// <param name="percentage">The percentage of cache entries to remove.</param> | ||
void Compact(double percentage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this return the number of elements removed? or a bool indicating if any elements were removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the argument is in percentage, it would probably make more sense to return the percentage of elements removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't seem very informative. Also, percentages are problematic if you remove 0/0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, since we are exposing Compact, should we expose Count on the interface as well? It's not a good way to gauge cache size but I suspect users will downcast and rely on it to determine how much to compact like in #252. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of using percentages is that they don't need to know the size. Otherwise Compact would take a specific amount. Or we shift it so Compact takes a specific number of elements to purge, returns the actual number removed, and expose Count. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then let's keep using percentages for both the amount to remove and amount removed. In the 0/0 case, just return 0. Returning the number of entry removed is rather strange considering a percentage was passed in. Returning a bool is also very uninformative. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Eilon except we've punted the decide-when-to-compact duty to the developer, and the number of elements in the cache is one inputs you'd use to decide when and how much to purge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JunTaoLuo put this on hold until we can sync in person Monday. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will probably solicit feedback from @davidfowl and @DamianEdwards as well if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think anyone can ever reason about how much to clear based on the number of items in the cache. Remember, the cache is generally a shared resource. Someone (including our own codes) might have stashed a thousand small objects there. Or 1 really ginormous one. But yes, let's discuss. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"OldTypeId": "public interface Microsoft.Extensions.Caching.Memory.IMemoryCache : System.IDisposable", | ||
"NewTypeId": "public interface Microsoft.Extensions.Caching.Memory.IMemoryCache : System.IDisposable", | ||
"NewMemberId": "System.Void Compact(System.Double percentage)", | ||
"Kind": "Addition" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"OldTypeId": "public interface Microsoft.Extensions.Caching.Memory.IMemoryCache : System.IDisposable", | ||
"NewTypeId": "public interface Microsoft.Extensions.Caching.Memory.IMemoryCache : System.IDisposable", | ||
"NewMemberId": "System.Void Compact(System.Double percentage)", | ||
"Kind": "Addition" | ||
} | ||
] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"OldTypeId": "public class Microsoft.Extensions.Caching.Memory.MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>", | ||
"OldMemberId": "public System.Boolean get_CompactOnMemoryPressure()", | ||
"Kind": "Removal" | ||
}, | ||
{ | ||
"OldTypeId": "public class Microsoft.Extensions.Caching.Memory.MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>", | ||
"OldMemberId": "public System.Void set_CompactOnMemoryPressure(System.Boolean value)", | ||
"Kind": "Removal" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"OldTypeId": "public class Microsoft.Extensions.Caching.Memory.MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>", | ||
"OldMemberId": "public System.Boolean get_CompactOnMemoryPressure()", | ||
"Kind": "Removal" | ||
}, | ||
{ | ||
"OldTypeId": "public class Microsoft.Extensions.Caching.Memory.MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>", | ||
"OldMemberId": "public System.Void set_CompactOnMemoryPressure(System.Boolean value)", | ||
"Kind": "Removal" | ||
} | ||
] |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the doc comment in
MemoryCache
itself to be a proper doc comment? Right now there are some odd///
comments there but not an actual doc comment.Caching/src/Microsoft.Extensions.Caching.Memory/MemoryCache.cs
Lines 275 to 281 in cd57aea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the implementation in
MemoryCache
doesn't do any argument validation, so that needs to be fixed as well.