Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appfabric cache clear all objects

Tags:

c#

appfabric

Is there a suggested method to just clear out all the objects in a DataCache ?

I could use the DataCache.GetObjectsByAllTags method but that required a region, which i cant use since i need to share objects among multiple cache hosts.

like image 465
np-hard Avatar asked Jun 20 '11 14:06

np-hard


2 Answers

There isn't a simple .Clear() on the DataCache object but using the following will clear the cache on the Appfabric hosts:

/* Assumes DataCache as a properly set up Microsoft.ApplicationServer.Caching.Client.DataCache object */

public void Clear()
{
   Parallel.ForEach(DataCache.GetSystemRegions(), region =>
   {
      DataCache.ClearRegion(region);
      var sysRegion = DataCache.GetSystemRegionName(region);
      DataCache.ClearRegion(sysRegion);
   });
}

The problem is, if you have DataCacheLocalCacheProperties set in your configuration you'll still be pulling items from local replica until timeout or notification occurs. I'm still looking for a way to invalidate items in the local replica immediately.

like image 129
PMontgomery Avatar answered Nov 04 '22 00:11

PMontgomery


Have a read of this answer: ASP.Net AppFabric Cache missing Flush/Clear and Count/GetCount methods?

like image 28
Matthew Abbott Avatar answered Nov 04 '22 00:11

Matthew Abbott