我想在 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
}
但是,当我尝试访问 DataCache(使用:dcf.GetCache("Vaibhav");
)时,这并没有按预期工作,它给出了 Cache not found 错误。当我使用 powershell 创建缓存时,它工作正常,并且我能够访问缓存,但我想以编程方式实现此目的,而不是通过命令提示符(powershell)
请建议一个正确的方法来实现这一点......
提前致谢 瓦伊巴夫
最佳答案
实际上,您必须以管理员身份启动 Visual Studio 才能以编程方式创建缓存。
关于caching - 在 Appfabric 中以编程方式添加命名数据缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8851894/