Getting list of cached objects

yeneralemdaroglu's Avatar


31 Aug, 2017 01:21 PM


Is there a way to get the list of cached objects so that an administrator can selectively remove cached items?



  1. Support Staff 1 Posted by PostSharp Techn... on 02 Sep, 2017 01:52 PM

    PostSharp Technologies's Avatar


    you can access your cache directly and use it to get the list of cached items. For example with MemoryCachingBackend you can do this:

                var cache = new MemoryCache("myCache");
                CachingServices.DefaultBackend = new MemoryCachingBackend(cache);

    Now, you can enumerate all cached key-value pairs:

    foreach (var pair in cache)
        Console.WriteLine($"{pair.Key}: {pair.Value}");

    You can remove cached items using the caching backend:


    or directly using the cache :


    If you are using cache dependencies, be careful when removing items directly from MemoryCache. It doesn't have any notion of dependency, so it is safer to use PostSharp API:


  2. Support Staff 2 Posted by PostSharp Techn... on 13 Sep, 2017 09:22 AM

    PostSharp Technologies's Avatar


    We are going to close this request as we believe it was solved. Please feel free to reopen the discussion if you need more help.

    Best regards,
    PostSharp Team

  3. PostSharp Technologies closed this discussion on 13 Sep, 2017 09:22 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac