I am trying to convert a solution using EntLib into using AppFabric caching. By help of a few extension methods this is a fairly pain-free process.
Extension methods
If anyone will have problems in future (like me) - here is the full code for clearing cache.
private static DataCacheFactory _factory;
private const String serverName = "";
private const String cacheName = "";
static void Main(string[] args)
{
Dictionary cacheHostsAndPorts = new Dictionary { { serverName, 22233 } };
Initialize(cacheHostsAndPorts);
DataCache cache = _factory.GetCache(cacheName);
FlushCache(cache);
Console.WriteLine("Done");
Console.ReadLine();
}
private static void FlushCache(DataCache cache)
{
foreach (string regionName in cache.GetSystemRegions())
{
cache.ClearRegion(regionName);
}
}
public static void Initialize(Dictionary cacheHostsAndPorts)
{
var factoryConfig = new DataCacheFactoryConfiguration
{
Servers = cacheHostsAndPorts.Select(cacheEndpoint => new DataCacheServerEndpoint(cacheEndpoint.Key, cacheEndpoint.Value))
};
_factory = new DataCacheFactory(factoryConfig);
}