Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to Microsoft.Extensions.Caching.Memory to 6.0.3 for netfx #3004

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,12 @@ public static void ChangeServerTceSetting(bool fEnable, SqlConnectionStringBuild

private static void ClearCache(MemoryCache cache)
{
// Get the Clear method of the cache and use it if available. This is available in Microsoft.Extensions.Caching 8.0
MethodInfo clearMethod = cache.GetType().GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public);
if (clearMethod != null)
{
clearMethod.Invoke(cache, null);
}
else
{
// Otherwise, use the Remove function to remove all entries using all keys in the cache gathered using reflection.
PropertyInfo cacheEntriesCollectionDefinition = typeof(MemoryCache).GetProperty("EntriesCollection", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EntriesCollection property was removed, causing the private reflection to fail.

ICollection cacheEntriesCollection = (ICollection)cacheEntriesCollectionDefinition.GetValue(cache);
List<ICacheEntry> cacheCollectionValues = new List<ICacheEntry>();

foreach (object cacheItem in cacheEntriesCollection)
{
ICacheEntry cacheItemValue = (ICacheEntry)cacheItem.GetType().GetProperty("Value").GetValue(cacheItem, null);
cache.Remove(cacheItemValue.Key);
}
}
#if NET
cache.Clear();
#else
// Compact with a target of 100% of objects is equivalent to clearing the cache
cache.Compact(1);
#endif
}
}
}
2 changes: 1 addition & 1 deletion tools/props/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<!-- NetFx and NetCore project dependencies -->
<PropertyGroup>
<AzureIdentityVersion>1.11.4</AzureIdentityVersion>
<MicrosoftExtensionsCachingMemoryVersion>6.0.1</MicrosoftExtensionsCachingMemoryVersion>
<MicrosoftExtensionsCachingMemoryVersion>6.0.3</MicrosoftExtensionsCachingMemoryVersion>
<MicrosoftIdentityModelJsonWebTokensVersion>7.5.0</MicrosoftIdentityModelJsonWebTokensVersion>
<MicrosoftIdentityModelProtocolsOpenIdConnectVersion>7.5.0</MicrosoftIdentityModelProtocolsOpenIdConnectVersion>
<SystemTextJsonVersion>6.0.10</SystemTextJsonVersion>
Expand Down
Loading