標籤: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’