gpt4 book ai didi

appfabric - 如何读取 Appfabric 缓存中存在的所有项目 :

转载 作者:行者123 更新时间:2023-12-04 00:42:23 25 4
gpt4 key购买 nike

我正在尝试开发一种工具(在 Visual Studio 2010 中,C#),它可以读取 Appfabric 缓存中存在的所有项目并将它们存储在表中。我不必使用 powershell。

首先我想到,如果我可以获取缓存中存在的所有区域,我可以使用 DataCache.GetObjectsInRegion 方法来完成我的任务。但是我无法从缓存中获取所有区域名称,因为它不显示用户定义的区域名称,而只显示默认区域名称,所以现在我放弃了这种方法。

谁能在这里指导我,我的主要目标是读取缓存中存在的所有项目。

最佳答案

没有内置方法来列出缓存中的所有项目。

您是对的,可以使用 GetObjectsInRegion 为命名缓存列出所有项目。您必须首先知道所有区域名称(如果使用)或调用 GetSystemRegions 以获取所有(默认)系统区域。一个简单的 foreach 将允许您列出所有项目。当您将没有区域名称的内容放入缓存时,它将被添加到系统区域。

这是一个基本的例子

    // Declare array for cache host(s).
DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
servers[0] = new DataCacheServerEndpoint("YOURSERVERHERE", 22233);

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

factoryConfig.SecurityProperties = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);

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

// Get a cache client for the default cache
DataCache myCache = mycacheFactory.GetDefaultCache(); //or change to mycacheFactory.GetCache(myNamedCache);

//inserty dummytest data
myCache.Put("key1", "myobject1");
myCache.Put("key2", "myobject2");
myCache.Put("key3", "myobject3");
Random random = new Random();

//list all items in the cache : important part
foreach (string region in myCache.GetSystemRegions())
{
foreach (var kvp in myCache.GetObjectsInRegion(region))
{
Console.WriteLine("data item ('{0}','{1}') in region {2} of cache {3}", kvp.Key, kvp.Value.ToString(), region, "default");
}
}

关于appfabric - 如何读取 Appfabric 缓存中存在的所有项目 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17546240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com