ASP.Net AppFabric Cache missing Flush/Clear and Count/GetCount methods?

前端 未结 2 1341
北海茫月
北海茫月 2021-01-05 08:06

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

2条回答
  •  我在风中等你
    2021-01-05 09:07

    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);
            }
    

提交回复
热议问题