在Appfabric中以编程方式添加命名数据缓存
问题描述:
我想在appfabric中以编程方式添加命名数据缓存。 我一直在下面的代码如下: -在Appfabric中以编程方式添加命名数据缓存
try
{
//This can also be kept in a config file
var config = new DataCacheFactoryConfiguration();
config.SecurityProperties = new DataCacheSecurity();
config.Servers = new List<DataCacheServerEndpoint> { new DataCacheServerEndpoint(Environment.MachineName, 22233) };
DataCacheFactory dcf = new DataCacheFactory(config);
if (dcf != null)
{
var state = InitialSessionState.CreateDefault();
state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" });
state.ThrowOnRunspaceOpenError = true;
var rs = RunspaceFactory.CreateRunspace(state);
rs.Open();
var pipe = rs.CreatePipeline();
pipe.Commands.Add(new Command("Use-CacheCluster"));
var cmd = new Command("New-Cache");
cmd.Parameters.Add(new CommandParameter("Name", "Vaibhav"));
cmd.Parameters.Add(new CommandParameter("Expirable", false));
pipe.Commands.Add(cmd);
var output = pipe.Invoke();
}
}
catch (Exception e)
{
//throw new Exception
}
但预期这不工作时,我试图访问数据高速缓存(使用:dcf.GetCache("Vaibhav");
)这是给高速缓存未找到错误。当我使用powershell创建缓存时,它工作正常,我能够访问缓存,但我想实现这个编程而不是通过命令提示符(powershell)
请建议一个正确的方法来实现这....
由于提前 Vaibhav的
答
你确实有启动Visual Studio中的管理员能够以编程方式创建缓存。
+0
好答案+1。 – 2012-01-23 10:20:18
你确定此代码正在工作吗?在控制台应用程序中运行此代码我得到一个CmdletInvocationException与一个消息“ErrorCode:SubStatus :错误:无法从注册表读取安装路径。”' –
PhilPursglove
2012-01-13 17:34:34
我没有得到任何错误,但我无法访问缓存 – Everest 2012-01-16 03:48:02