大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
AppFabric的开发相对还是很简单的,最常见的方法无非是声明一个缓存接口,然后由各种缓存实现.
具体的使用除了msdn:
http://msdn.microsoft.com/zh-cn/library/hh334305
这是实例包的下载地址:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=19603
这篇博客介绍得不错.
使用微软分布式缓存服务Velocity(Windows Server AppFabric Caching Service)
概述
配置模型
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="dcache" type="System.Data.Caching.DCacheSection, CacheBaseLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> </configSections> <dcache cluster="localhost" size="Small"> <caches> <cache type="partitioned" consistency="strong" name="default"> <policy> <eviction type="lru" /> <expiration defaultTTL="10" isExpirable="true" /> </policy> </cache> <cache type="partitioned" consistency="strong" name="other"> <policy> <eviction type="lru" /> <expiration defaultTTL="10" isExpirable="true" /> </policy> </cache> </caches> <hosts> <host clusterPort="22234" hostId="1319514812" size="1024" quorumHost="true" name="TERRYLEE-PC" cacheHostName="DistributedCacheService" cachePort="22233" /> </hosts> <advancedProperties> <partitionStoreConnectionSettings providerName="System.Data.SqlServerCe.3.5" connectionString="D:\CacheShare\ConfigStore.sdf" /> </advancedProperties> </dcache> </configuration>
<section name="dcacheClient" type="System.Data.Caching.DCacheSection, CacheBaseLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
<dcacheClient> <localCache isEnabled="true" sync="TTLBased" ttlValue="300" /> <hosts> <host name="localhost" cachePort="22233" cacheHostName="DistributedCacheService"/> </hosts> </dcacheClient>
缓存复杂数据类型
[Serializable] public class Customer { public String ID { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public int Age { get; set; } public String Email { get; set; } }
Cache cache = GetCurrentCache(); Customer customer = new Customer() { ID = "C20081117002", FirstName = "Terry", LastName = "Lee", Age = 25, Email = "lhj_cauc[#AT#]163.com" }; cache.Add(customer.ID, customer);
Cache cache = GetCurrentCache(); Customer customer = cache.Get("C20081117002") as Customer;
Cache cache = GetCurrentCache(); cache.Remove("C20081117002");
Cache cache = GetCurrentCache(); Customer customer = new Customer() { ID = "C20081117002", FirstName = "Huijui", LastName = "Li", Age = 26, Email = "lhj_cauc[#AT#]163.com" }; cache["C20081117002"] = customer;
Cache cache = GetCurrentCache(); Customer customer = new Customer() { ID = "C20081117002", FirstName = "Huijui", LastName = "Li", Age = 26, Email = "lhj_cauc[#AT#]163.com" }; cache.Put(customer.ID, customer);
使用分区
public void ClearRegion(string region); public bool CreateRegion(string region, bool evictable); public bool RemoveRegion(string region);
Cache cache = GetCurrentCache(); string regionName = "Customers"; cache.CreateRegion(regionName, false); Customer customer = new Customer() { ID = "C20081117003", FirstName = "Terry", LastName = "Lee", Age = 25, Email = "lhj_cauc[#AT#]163.com" }; cache.Add(regionName, customer.ID, customer);
使用标签
Cache cache = GetCurrentCache(); string regionName = "Customers"; Customer customer1 = new Customer() { ID = "C20081117004", FirstName = "Terry", LastName = "Lee", Age = 25, Email = "lhj_cauc[#AT#]163.com" }; Customer customer2 = new Customer() { ID = "C20081117005", FirstName = "Terry", LastName = "Lee", Age = 25, Email = "lhj_cauc[#AT#]163.com" }; Tag tag1 = new Tag("Beijing"); Tag tag2 = new Tag("Tianjin"); cache.Add(regionName, customer1.ID, customer1, new Tag[] { tag1, tag2 }); cache.Add(regionName, customer2.ID, customer2, new Tag[] { tag2 });
GetAllMatchingTags(string region, Tag[] tags) GetAnyMatchingTag(string region, Tag[] tags) GetByTag(string region, Tag tag)
string regionName = "Customers"; Tag[] tags = new Tag[] { new Tag("Beijing"), new Tag("Tianjin")}; List<KeyValuePair<string, object>> result = cache.GetAllMatchingTags(regionName, tags);
ASP.NET SessionState提供者
<section name="dcacheClient" type="System.Data.Caching.DCacheSection, CacheBaseLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
<dcacheClient> <localCache isEnabled="true" sync="TTLBased" ttlValue="300" /> <hosts> <host name="localhost" cachePort="22233" cacheHostName="DistributedCacheService"/> </hosts> </dcacheClient>
<sessionState mode="Custom" customProvider="Velocity"> <providers> <add name="Velocity" type="System.Data.Caching.SessionStoreProvider,ClientLibrary" cacheName="default"/> </providers> </sessionState>
总结
本文出自 “TerryLee技术专栏” 博客,请务必保留此出处http://terrylee.blog.51cto.com/342737/151964
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181014.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...