質問は、AppFabric を構成している場所について少しあいまいです。Scott Hanselman によるものなど、AppFabric キャッシュを構成するための多くの Google 検索結果の 1 つの手順を実行したと仮定します。そのリンクで彼の CacheUtil クラスを見ると、2 つのキャッシュにアクセスするように変更できます。
using Microsoft.ApplicationServer.Caching;
using System.Collections.Generic;
public class CacheUtil
{
private static DataCacheFactory _factory = null;
private static DataCache _NamedCache1 = null;
private static DataCache _NamedCache2 = null;
public static DataCache GetNamedCache1()
{
if (_NamedCache1 != null)
return _NamedCache1;
//Define Array for 2 Cache Hosts
List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(2);
//Specify Cache Host Details
// Parameter 1 = host name
// Parameter 2 = cache port number
servers.Add(new DataCacheServerEndpoint("X1", 22233));
servers.Add(new DataCacheServerEndpoint("X2", 22233));
//Create cache configuration
DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
//Set the cache host(s)
configuration.Servers = servers;
//Set default properties for local cache (local cache disabled)
configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
//Disable tracing to avoid informational/verbose messages on the web page
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
//Pass configuration settings to cacheFactory constructor
_factory = new DataCacheFactory(configuration);
//Get reference to named cache called "default"
_NamedCache1 = _factory.GetCache("NamedCache1");
return _NamedCache1;
}
public static DataCache GetNamedCache2()
{
if (_NamedCache2 != null)
return _NamedCache2;
//Define Array for 2 Cache Hosts
List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(2);
//Specify Cache Host Details
// Parameter 1 = host name
// Parameter 2 = cache port number
servers.Add(new DataCacheServerEndpoint("X1", 22233));
servers.Add(new DataCacheServerEndpoint("X2", 22233));
//Create cache configuration
DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
//Set the cache host(s)
configuration.Servers = servers;
//Set default properties for local cache (local cache disabled)
configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
//Disable tracing to avoid informational/verbose messages on the web page
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
//Pass configuration settings to cacheFactory constructor
_factory = new DataCacheFactory(configuration);
//Get reference to named cache called "default"
_NamedCache2 = _factory.GetCache("NamedCache2");
return _NamedCache2;
}
}