Windows Server AppFabric

 最近项目中用到微软的分布缓存 记录下 

1.系统 win7 64位

下载安装程序

IIS Manager for Remote Administration  
http://www.iis.net/downloads/microsoft/iis-manager 

Windows Server AppFabric

http://www.microsoft.com/zh-cn/download/details.aspx?id=15848

 

依次安装上面文件 并设置

 

执行 ProwerShell 命令:

1.Start-CacheCluster 启动集群

2.Get-CacheHost 得到host

3.Grant-CacheAllowedClientAccount 域\用户名  用户 授权

4.Get-CacheAllowedClientAccounts 得到所有用户授权

 

 

C# Code

 static void Main(string[] args)

        {

            //实例化配置

            DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();



            //定义缓存主机

            List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);

            servers.Add(new DataCacheServerEndpoint(Environment.MachineName, 22233));



            configuration.Servers = servers;



            // 定义配置的安全性能属性

            configuration.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);



            configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();



            DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);



            var _factory = new DataCacheFactory(configuration);



            //层次关系 Machine->CacheHost->Named Cache->Region->CacheItems->Object

            //创建数据缓存

            //这里测试创建2个数据缓存(Named Cache) 每个缓存里面有两个区域缓存(Region)

            Dictionary<string, DataCache> dataCache = new Dictionary<string, DataCache>(2);

            dataCache["default"] = _factory.GetCache("default");

            dataCache["default"].CreateRegion("OrderData_Cache");

            dataCache["default"].CreateRegion("ProductData_Cache");



            //dataCache["secone"] = _factory.GetCache("secone");

            //dataCache["secone"].CreateRegion("HrData_Cache");

            //dataCache["secone"].CreateRegion("ConsumerData_Cache");





            Console.WriteLine("添加缓存数据....");

            //添加数据

            

                dataCache["default"].Add("lvxiaojia", "Hello Word!", "OrderData_Cache");

            

                dataCache["default"].Add("xiaojia", "How Are You", "ProductData_Cache");





            //Console.ReadLine();

            Console.WriteLine("开始读取缓存读取....");

            Console.WriteLine(dataCache["default"].Get("lvxiaojiakey", "OrderData_Cache").ToString());

            Console.WriteLine(dataCache["default"].Get("xiaojiakey", "ProductData_Cache").ToString());

            Console.ReadLine();



        }

 

 

 

 

你可能感兴趣的:(windows)