0

I am doing a project and my requirement is to basically implement a Coherence Cache Dashboard. The basic idea is to fetch all the keys stored in the Coherent Cache. Is there a command or any other way to fetch all cache keys from distributed coherent cache?

    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;

    }

By doing this, i can iterate over cache keys created by the current cache manager. But, how can I find keys created by other cache managers in a partitioned coherent cache?

Codez
  • 35
  • 7

1 Answers1

0

This is a simple command:

 NamedCache<String, String> cache = CacheFactory.getCache(CACHENAME, String.class, String.class);
 Set<String> keys = cache.keySet();
  • Thanks for the answer. But using this command can I retrieve keys of a partitioned cache? I think this will only work for NamedCache – Codez May 31 '20 at 06:49
  • The PartitionedCache is the specific implementation for the distributed cache but client side when you want to use it you can use the class CacheFactory to obtain a NamedCache reference for the partitioned cache. You don't use the partitioned cache but at client side you should use the named cache class that hides the real implementation. I update my script. Try it! – Simone Casamassa Jun 01 '20 at 09:02
  • Okay. Is there any UNIX script for the same which I could run to retrieve the keys? – Codez Jun 05 '20 at 11:33
  • No, you have to use the API . Then there's the Coherence query language to read coherence data from wlst console. – Simone Casamassa Jun 05 '20 at 13:55
  • Yeah. I am trying to use Cohql query in Production. But i am getting this error "no storage-enabled nodes exist for service partitionedcache" when I am trying to use the command - select * from "cachename". Although, the cache contains some data. – Codez Jun 06 '20 at 07:37