使用微软分布式缓存服务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
使用微软分布式缓存服务Velocity(Windows Server AppFabric Caching Service)的更多相关文章
- Windows Server AppFabric分布式缓存研究
分享一则先前对Windows Server AppFabric分布式缓存的技术研究. 一. AppFabric 技术架构和原理 AppFabric与Memcached类似,采用C/S的模式,在 ser ...
- 如何用分布式缓存服务实现Redis内存优化
Redis是一种支持Key-Value等多种数据结构的存储系统,其数据特性是“ALL IN MEMORY”,因此优化内存十分重要.在对Redis进行内存优化时,先要掌握Redis内存存储的特性比如字符 ...
- 误解了Windows Server AppFabric
想为自己的流程引擎找一个宿主,选择了几套方案,想先从AppFabric开始,原因主要出于以下几点: 1. 自己用过Windows Service或Form作为一些定时任务等应用的宿主,但苦于学艺不精, ...
- Windows Server AppFabric 安装文档
安装指南 入门标题页 3 Windows Server AppFabric 安装和配置指南 3 版权 3 版权所有 3 简介 3 清单:规划安装 4 硬件要求 4 使计算机作好安装准备 5 本节内容 ...
- 浅谈Windows Server APPFABRIC
hi,everyone !真的是好久好久没有update blog了,因为最近忙着备考,没有时间对<数据结构与算法>进行研究学习了.所以,blog一直未更新.today is Friday ...
- SharePoint 2013 必备组件之 Windows Server AppFabric 安装错误
1.如下图,在使用SharePoint2013产品准备工具的时候,网上下载安装Windows Server AppFabric的时候,报错,点击完成重启计算机,重新安装依然报错. 2.无奈之下,只有选 ...
- Windows Server AppFabric
文章:Windows Server AppFabric简介 介绍了AppFabric强大的功能.
- 微软分布式缓存 appfabric
appfabric为微软自家产的分布式缓存解决方案,随dotnet4.0一起发布.目前版本为1.1
- 华为云分布式缓存服务DCS与开源服务差异对比
华为云分布式缓存DCS提供单机.主备.集群等丰富的实例类型,满足用户高读写性能及快速数据访问的业务诉求.支持丰富的实例管理操作,帮助用户省去运维烦恼.用户可以聚焦于业务逻辑本身,而无需过多考虑部署.监 ...
随机推荐
- UITableView加载显示更多内容
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end #import "ViewCo ...
- 使用block来解决实现switch解决字符串
NSString *lookup=@"Hearts"; typedef void (^CaseBlock)(); NSDictionary *diction=@{@"D ...
- NSURLConnection & NSRULSession
NSURLConnection & NSRULSession NSURLSession是NSURLConnection 的替代者,在2013年苹果全球开发者大会(WWDC2013)随ios7一 ...
- C#中的virtual & override
很奇怪的设计,需要靠着两个Keyword共同作用,才能完成多态——而不是类似Java那样的默认多态.所谓共同作用,即基类使用virtual 标示函数,子类使用override显示重写. 有点奇怪,MS ...
- 剑指Offer39 数组中寻找和为sum的两个数字
/************************************************************************* > File Name: 39_TwoNum ...
- 剑指Offer46 求1+2+...+n
/************************************************************************* > File Name: 46_Accumu ...
- Python之类型转换
函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数 complex(real [,imag]) ...
- sql获取exec('')的返回值
) ) select @sql=('select @a=cNumber+1 from VoucherHistory where CardNumber='''+@CardNumber+'''') exe ...
- Java之循环语句练习1
最近在猛复习Java,猛刷题目ing.这个做题目的过程其实也就像搬砖一样,一点一点把最基础的巩固好,一块一块.整整齐齐地砌才能砌好一面墙.好了,不说了,我要去搬砖了. 其实不瞒你们说,我是比较喜欢数学 ...
- Windows 10 (or 8)Chrome 观看视频发生flash不能加载,即"could't load plugins"原因之一
最近一直如题,不能看视频,后来发现从一个已经使用管理员权限打开的应用转到Chrome就可以加载flash,而从桌面打开Chrome就加载不了. 今天再次查找信息,从Ubuntu下Chrome不能加载f ...