我正在做一个项目,我的要求是基本上实现一个Coherence Cache Dashboard。基本思想是获取存储在一致性缓存中的所有密钥。是否有命令或任何其他方式可从分布式一致性缓存中获取所有缓存键?
public void printAllCache(){
Cache<String, String> cache = cacheManager.getCache(CACHENAME,
String.class, String.class);
Iterator<Cache.Entry<String,String>> allCacheEntries= cache.iterator();
while(allCacheEntries.hasNext()){
Cache.Entry<String,String> currentEntry = allCacheEntries.next();
System.out.println("Key: "+currentEntry.getKey()+" Value: "+
currentEntry.getValue());
}
return returnProperties;
}
通过这样做,我可以遍历当前缓存管理器创建的缓存键。但是,如何在分区一致的缓存中找到其他缓存管理器创建的键?
这是一个简单的命令:
NamedCache<String, String> cache = CacheFactory.getCache(CACHENAME, String.class, String.class);
Set<String> keys = cache.keySet();