微软分布式缓存,工程代码为“Velocity”。这是一个分布式内存对象缓存系统。最新版本为CTP3。下载
跟memcached一样,“Velocity”维护一张大的哈希表,这张表可以跨越多个服务器,你可以通过添加或者减少服务器来平衡系统压力。
安装“Velocity ”时需要建立一个保存配置的地方,可以是共享文件,也可以是SQLServer数据库。
安装完成后需要用Run as administrator来运行它。
接下来我们要启动它。命令为:start-cachecluster.

然后加入一个新的Cache,名称为“testcache”.命令为:
new-cache -cachename testcache
下面我们要在系统中使用“Velocity ”。
首先要引用CacheBaseLibrary.dll 和 ClientLibrary.dll。然后在配置文件中加入
[xhtml]
view plain
copy
- <configSections>
- <section name="dataCacheClient" type="Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/>
- </configSections>
和
[xhtml]
view plain
copy
- <sessionState mode="Custom" customProvider="Velocity">
- <providers>
- <add name="Velocity" type="Microsoft.Data.Caching.DataCacheSessionStoreProvider, ClientLibrary" />
- </providers>
- </sessionState>
最后就是使用了,下面是
加入一个缓存:
[c-sharp]
view plain
copy
- DataCacheFactory dcf = new DataCacheFactory();
- DataCache dcfcontrin = dcf.GetCache("testcache");
- //加入一个,绝对过期时间为10秒
- dcfcontrin.Add("test", "ok",new TimeSpan (0,0,10));
还有其他方法 Put,Remove,Get.

被折叠的 条评论
为什么被折叠?



