开发者

appfabric cache clear all objects

开发者 https://www.devze.com 2023-03-13 23:26 出处:网络
Is there a suggested method to just clear out all the objects in a DataCache ? I could use the D开发者_运维百科ataCache.GetObjectsByAllTags method but that required a region, which i cant use since i

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

I could use the D开发者_运维百科ataCache.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.


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


$hostname = 'server.lan'
$endpoints = New-Object -TypeName System.Collections.Generic.List[Microsoft.ApplicationServer.Caching.DataCacheServerEndpoint]
$endpoints.Add((New-Object -TypeName Microsoft.ApplicationServer.Caching.DataCacheServerEndpoint -ArgumentList $hostname, 22233))
$cache = ( New-Object -TypeName Microsoft.ApplicationServer.Caching.DataCacheFactory -ArgumentList ( New-Object -TypeName Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration -Property @{ Servers = $endpoints } ) ).GetCache('Pricing')
$cache.GetSystemRegions() | %{ $cache.ClearRegion( $_ ) }


This is the method to flush the cache that I used. To verify that the cache items were cleared, I ran get-cachestatistics in the command shell.

public void Clear()
{
   Parallel.ForEach(DataCache.GetSystemRegions(), new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, region =>
   {
      DataCache.ClearRegion(region);
   });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号