0

There are options to read the cache by using keys. Like this :

   Collection<Integer> userIds = context.getUserDao().allUserIds();  
   for (Integer userId : userIds) {
        User user = cache.getUserCache().get(userId);
        System.out.println(user.toString());
    }

With the latter it will load the expired ones to the cache and then display it.

But the requirement is to view all the content currently in the cache.

Shenal
  • 202
  • 5
  • 21

2 Answers2

6

This is how to view all the content of the Cache. Found the method after going through the Java Docs of JCache.

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;

}
Shenal
  • 202
  • 5
  • 21
0

See if the following link is of help https://docs.oracle.com/middleware/1213/coherence/develop-applications/jcache_basic.htm#COHDG5812

Ahsen
  • 386
  • 4
  • 18
  • This only gives the way to get data for known keys. What I want to know is getting all the content of the cache without knowing the keys. – Shenal Nov 19 '14 at 07:55