asp.net 分布式緩衝

來源:互聯網
上載者:User

標籤:style   blog   color   width   get   int   

之前Velocity已被 整合到App Fabric(包含有WCF監控==)中.

 

網路Velocity使用大多是針對老版本: 
老版本的:  http://www.microsoft.com/en-us/download/details.aspx?id=2517

 

這裡針對App Fabric做一些說明:

1. 在VS 2010中使用:

1) 在App Fabric的安裝目錄中引用:

Microsoft.ApplicationServer.Caching.Client.dll

Microsoft.ApplicationServer.Caching.Core.dll

Microsoft.ApplicationServer.Caching.Core.dll 是Cache基底類別庫,Cache用戶端和服務端都引用該DLL,包含配置庫和基類緩衝類型。

Microsoft.ApplicationServer.Caching.Client.dll 包含Cache用戶端類庫,如串連到Cache cluster儲存和檢索資料的API介面等等。

 

2) Web.config中配置 (可參考:http://msdn.microsoft.com/zh-cn/library/ee790859(v=azure.10).aspx)

<configSections>
        <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
    </configSections>
    <dataCacheClient>
        <hosts>
            <host name="Cache伺服器主機名稱" cachePort="22233" />
        </hosts>
    </dataCacheClient>

 

3)代碼:

           string key = "ApplicationName";
           var dcf = new DataCacheFactory();

           if (dcf != null)
           {
               var cache = dcf.GetCache("default");    //這個要為Cache伺服器中有效Cache名稱, 不然會報錯.
               name = cache.Get(key) as string;
               if (name == null)
               {
                   name = "Windows Server App Fabric Cache Lab";
                   cache.Put(key, name);
               }
           }
          

在Power shell工具中查詢Cache名稱的方法:


 

2. VS2010中不使用設定檔串連緩衝

        DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
          servers[0] = new DataCacheServerEndpoint("Cache伺服器的主機名稱", 22233);

          // Setup the DataCacheFactory configuration.
          DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();
          factoryConfig.Servers = servers;

          // Create a configured DataCacheFactory object.
          DataCacheFactory mycacheFactory = new DataCacheFactory(factoryConfig);

          // Get a cache client for the cache "NamedCache1".
          DataCache myDefaultCache = mycacheFactory.GetCache("default");
          myDefaultCache.Put("ApplicationName1", "vvvv");
          object v = myDefaultCache.Get("ApplicationName1");

 

 

常用Power shell命令:

1. get-command *cache* :尋找包含有cache關鍵字的命令

2. get-cache: 擷取當前伺服器的緩衝名稱

3. new-cache:建立緩衝. 在Cache伺服器共用設定檔中會自動添加新的緩衝節點
例: new-cache ‘aaa’

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.