The MemoryCache class does not have a "Clear()" method.
Here is an extension that does the job
Here is an extension that does the job
// Extend MemoryCache functionality
public static class MemoryCacheExtensions
{
// Clear the cache
public static void Clear(this MemoryCache cache)
{
List<string> cacheKeys = cache.Select(kvp => kvp.Key).ToList();
foreach (string cacheKey in cacheKeys)
{
cache.Remove(cacheKey);
}
}
}
No comments:
Post a Comment