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