none
How do you flush/clear the entire AppFabric Cache?

    Question

  • I'm looking for a way to flush all data out of a specific Cache.
    http://www.IActionable.com - Game Mechanics as a Service
    Thursday, May 05, 2011 6:08 PM

All replies

  • You can find the API from here: http://msdn.microsoft.com/en-us/library/microsoft.applicationserver.caching.datacache_members(v=WS.10).aspx.

    Some methods are limited support in Windows Azure AppFabric Cache, please see http://msdn.microsoft.com/en-us/library/gg278350.aspx.

    Since currently Windows Azure AppFabric Cache does not support named region, you might use GetSystemRegions method to get the default region and then call ClearRegion method to clear cached objects in that region.

    Friday, May 06, 2011 10:56 AM
  • Unfortunately that solution does not work.

    Calling GetSystemRegions or ClearRegion throws an exception saying that it is not supported by the cache.


    http://www.IActionable.com - Game Mechanics as a Service



    Friday, May 06, 2011 5:09 PM
  • Can you describle the scenario where flusing all data from a cache is required? Currently this is not supported.
    Monday, May 09, 2011 10:46 AM
  • When I'm unit testing and benchmarking code I would like to start with what I know is a completely empty cache.

    It would also be nice to be able to test code against the scenario of my cache data being completely lost and making sure the system can recover quickly.

    Whenever I change the key structure/pattern I would like to flush it to ensure there aren't any collisions by removing all the items.

    I would also like control over the cache in case production bugs have introduce some abnormalities in the data or aren't refreshing properly.


    http://www.IActionable.com - Game Mechanics as a Service
    Monday, May 09, 2011 3:32 PM
  • You could always append a version number or some other prefix/suffix to your cache keys (e.g. itemOne-v1, itemTwo-v1). Then, whenever you need to clear the cache, you increment the version number or change the suffix (e.g. item0ne-v2, itemTwo-v2). This ensures that after the change, you will always get a cache miss and, because the eviction policy of the cache removes least-recently-used items, any new items added to the cache will eventually replace old items.

     

    • Marked as answer by Wenchao Zeng Thursday, May 12, 2011 7:14 AM
    • Unmarked as answer by IA JBarnes Thursday, August 04, 2011 2:23 PM
    Monday, May 09, 2011 3:50 PM
  • "Can you describle the scenario where flusing all data from a cache is required?"

    I don't mean to be rude but isn't this just the most ridiculous question? Isn't it akin to describing the scenario for choosing to jump from a skyscraper?  Maybe we like base jumping, or perhaps it's burning, or it's suicide, or we didn't know it was so high, or we were trying to clear the gap onto the other roof, or we thought god might save us if we beleived hard enough, or it was so windy i figured i would blow back up and be ok...etc. etc. etc.

    Isn't it enough that this guy just described a requirement for it and that therefore the scenario exists?

    The first thing i needed was to clear down my cache after tinkering with it.  Why? Because i'm just plain lazy sometimes and figured i'd like to start again, mmm not unlike my unit tests too.

    Cheers

     

    J

    Thursday, August 04, 2011 1:54 PM
  • Isn't it enough that this guy just described a requirement for it and that therefore the scenario exists?

    Thanks for the support :) 

    You could always append a version number or some other prefix/suffix to your cache keys (e.g. itemOne-v1, itemTwo-v1). Then, whenever you need to clear the cache, you increment the version number or change the suffix (e.g. item0ne-v2, itemTwo-v2). This ensures that after the change, you will always get a cache miss and, because the eviction policy of the cache removes least-recently-used items, any new items added to the cache will eventually replace old items.

    I tried to go down this path and it just isn't manageable. I don't like the idea of someone needing to change a production environment config or re-deploy a role in order to modify this 'magic' key. In a perfect world, I would prefer to have this has an option in the Management Portal as button that flushes everything on demand.


    http://www.IActionable.com - Gamification and Analytics Platform


    Thursday, August 04, 2011 2:05 PM
  • Now here's a cracking example scenario. All the serialized instances in the cache are no longer valid for the updated code I'm about to release as out of neccesity i had to break the contract.  I need that cache splatting.

    Thursday, August 04, 2011 2:09 PM
  • Here's another scenario, if you need it:

    I load the cache with the totality of a set A that represents my universe of values.

    Then one node goes down in a non-HA cluster taking with it all values hashed to that node.

    Now my universe and cache is corrupt and I need to reload it.

    So, I would a) flush it and b) reload it

    The Flush() is simply not available. And, no, Restart-CacheNode or Restart-CacheCluster won't get me there and may restart other caches that need to be unaffected by the corruption.

     

    And stop giving these over-engineering answers like: "create your own namespace" and "enumerate the regions". Avoiding this type of complexity is why I didn't code this to my own static structure to begin with!! AND PLUS...every other caching API has a Flush() command!!!!!

    Memcached = flush_all

    NCache = Clear()

    SharedCache = Clear()

    need I go on...?? ADD IT MICROSOFT!!! and get these engineers to stop creating useless solutions...please!

    Friday, October 28, 2011 1:26 AM
  • Jeff, apologies for the inconvenience caused. There is no method right now in cache for Clear() but we will add it in future.
    Thursday, February 23, 2012 5:17 AM
  • When? I have this exact problem. I've changed some of the objects being serialized and now all I get are exceptions, exceptions and exceptions.  There's no purpose in having a cache that you can't get rid of, eventually. 

    Monday, March 12, 2012 5:20 PM
  • This is a highly requested feature for many of us. Hopefully when the next changes are coming, it'll be implemented.

    For now it's keeping a list of all items you've stored and retrieved from the cache the clear it and make sure to play well with the timeout based invalidation policy.


    Be nice to nerds ... Chances are you'll end up working for one!

    Monday, March 12, 2012 8:21 PM
  • this is ridiculous that you can't actively clear appfabric cache. we need, in fact MUST be able to clear cache on demand throughout the day and night. for example, if we're caching data that comes from what we call 'content blocks' which is managed by another department. when these bits of html are updated, we need to be able to invalidate the old one and update it with the new bit of data.

    i'm extremely surprised to hear there's no method for this.

    Thursday, May 10, 2012 5:15 PM
  • Of course it's ridiculous. I dropped the whole thing and went to a memcached implementation. Works like a charm. Has a flush.

    Thursday, May 10, 2012 5:24 PM
  • here's something i just wrote that seems it might work. it iterates the default cache and resets all keys' time to expire and sets it to 01 millisecond (basically immediately). 

    public static void Flush()
            {
                var cache = GetCache();
                foreach (var obj in cache.GetSystemRegions().SelectMany(cache.GetObjectsInRegion))
                {
                    cache.ResetObjectTimeout(obj.Key, new TimeSpan(0,0,0,0,01)); //set to expire basically immediately
                }
            }

    Thursday, May 10, 2012 7:38 PM
  • This doesn't work in Azure.  Regions aren't supported.

    When will this function get added?  I'm getting charged for abandoned items in the cache because I can't clear them and I don't have the keys.

    Tuesday, November 20, 2012 11:03 PM