VENDAS: 1-800-867-1389

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

    Pergunta

  • I'm looking for a way to flush all data out of a specific Cache.
    http://www.IActionable.com - Game Mechanics as a Service
    quinta-feira, 5 de maio de 2011 18:08

Todas as Respostas

  • 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.

    sexta-feira, 6 de maio de 2011 10:56
  • 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



    sexta-feira, 6 de maio de 2011 17:09
  • Can you describle the scenario where flusing all data from a cache is required? Currently this is not supported.
    segunda-feira, 9 de maio de 2011 10:46
  • 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
    segunda-feira, 9 de maio de 2011 15:32
  • 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.

     

    • Marcado como Resposta Wenchao Zeng quinta-feira, 12 de maio de 2011 07:14
    • Não Marcado como Resposta IA JBarnes quinta-feira, 4 de agosto de 2011 14:23
    segunda-feira, 9 de maio de 2011 15:50
  • "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

    quinta-feira, 4 de agosto de 2011 13:54
  • 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


    quinta-feira, 4 de agosto de 2011 14:05
  • 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.

    quinta-feira, 4 de agosto de 2011 14:09
  • 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!

    sexta-feira, 28 de outubro de 2011 01:26
  • Jeff, apologies for the inconvenience caused. There is no method right now in cache for Clear() but we will add it in future.
    quinta-feira, 23 de fevereiro de 2012 05:17
  • 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. 

    segunda-feira, 12 de março de 2012 17:20
  • 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!

    segunda-feira, 12 de março de 2012 20:21
  • 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.

    quinta-feira, 10 de maio de 2012 17:15
  • Of course it's ridiculous. I dropped the whole thing and went to a memcached implementation. Works like a charm. Has a flush.

    quinta-feira, 10 de maio de 2012 17:24
  • 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
                }
            }

    • Sugerido como Resposta Francois Germain sexta-feira, 25 de outubro de 2013 16:58
    quinta-feira, 10 de maio de 2012 19:38
  • 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.

    terça-feira, 20 de novembro de 2012 23:03