微軟分布式緩衝AppFabric(Velocity)-開發篇(一)開發環境準備

來源:互聯網
上載者:User

配置好快取叢集時,在windows services 中啟動名為:Microsoft project code named “Velocity”的服務,該服務預設不會自動啟動

1. 將Volocity的程式集copy到開發機器上。程式集位於Velocity的安裝目錄。程式集如下:

CacheBaseLibrary.dll,

ClientLibrary.dll,

 FabricCommon.dll,

 CASBase.dll.

2.在VS的工程中添加以上程式集的引用

3.配置快取用戶端的xml設定檔一般為.config檔案,或直接在代碼裡指定配置

選擇用Routing Cleing或Simple Client,選擇Routing Client會獲得最佳的效能。

 

Demo:

下面是一個Routing Client的配置樣本。樣本中未啟用本機快取,但使用了兩個緩衝主機:CacheServer1和CacheServer2

<?xml version="1.0" encoding="utf-8" ?><configuration>    <!--configSections must be the FIRST element -->  <configSections>        <!-- required to read the <dataCacheClient> element -->    <section name="dataCacheClient"       type="Microsoft.Data.Caching.DataCacheClientSection,       CacheBaseLibrary"       allowLocation="true"       allowDefinition="Everywhere"/>        <!-- required to read the <fabric> element, when present -->    <section name="fabric"       type="System.Data.Fabric.Common.ConfigFile,       FabricCommon"       allowLocation="true"       allowDefinition="Everywhere"/>      </configSections>    <!-- routing client-->  <dataCacheClient deployment="routing">    <!-- (optional) specify local cache     <localCache      isEnabled="true"      sync="TTLBased"      objectCount="100000"      ttlValue="300" />    -->    <!--(optional) specify cache notifications poll interval     <clientNotification pollInterval="300" />    -->        <!-- cache host(s) -->        <hosts>      <host         name="CacheServer1"         cachePort="22233"         cacheHostName="DistributedCacheService"/>      <host         name="CacheServer2"         cachePort="22233"         cacheHostName="DistributedCacheService"/>    </hosts>  </dataCacheClient></configuration>

 

 

下面代碼示範如何在代碼中指定配置

//declare array for cache host(s)DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];//specify cache host(s)servers[0] = new DataCacheServerEndpoint("CacheServer2",                         22233, "DistributedCacheService");//specify cache client configurationDataCacheFactory mycacheFactory     = new DataCacheFactory(servers, true, false);//get cache client for cache "NamedCache1"DataCache myDefaultCache = mycacheFactory.GetCache("NamedCache1");

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.