Search

MemoryCache class needs a Clear() method by Andrew Mackie

Closed
as Deferred Help for as Deferred

5
0
Sign in
to vote
Type: Bug
ID: 723620
Opened: 2/6/2012 5:06:52 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
0
User(s) can reproduce this bug
The .NET 4 MemoryCache class in System.Runtime.Caching needs a Clear() method, to allow completely clearing the MemoryCache.Default cache. There is no such method.

You could get an enumerator and individually remove all keys, but the MSDN documentation says don't use the GetEnumerator method!


Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

Write code such as MemoryCache.Default.Clear(); in a C# program and you get a compile time error. There is no means to completely clear the cache.

Product Language

English

Operating System

Windows Server 2008 R2

Operating System Language

English

Actual results

Compile time error - Clear() method doesn't exist

Expected results

Clear() method should exist and clear the MemoryCache.Default cache.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/4/2012 at 9:23 AM
Closing this bug for now. Product team will take a look at this suggestion for future release.
Posted by Microsoft on 2/8/2012 at 3:14 PM
Thank you for the suggestion. We're tracking this internally for a future release.
Posted by MS-Moderator08 [Feedback Moderator] on 2/6/2012 at 6:51 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 2/6/2012 at 5:41 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Andrew Mackie on 2/9/2012 at 12:52 AM
--Could write code such as the following as a workaround, but the MSDN documentation says not to use enumerators in production on MemoryCache as it is a blocking call

            List<string> cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
            foreach (string cacheKey in cacheKeys)
                MemoryCache.Default.Remove(cacheKey);