0
votes

How do I get all entries available in 2nd Level Cache?

My application do a re-cache by cache.removeAll(); and list all() so in the Hibernate 2nd Level. It will have all the entries I need cached.

and During this 15 mins.. I only wish to getAll Entries from the 2nd level (without hitting DB)

I do no wish use hibernate query because the under lining change often.

What other options do I have?

1
im guessing you are having a 15 minute timeout for the cache.. you can use the CacheManager to get access to the cache and list items in the cache. - Anantha Sharma
they are stored in de-hydrated mode. - seesee
have you tried to get all cache elemensts... ehcache.org/apidocs/net/sf/ehcache/… - Anantha Sharma
yes like I say they are stored in De-hydrated.. so it won't be the actual element. and how do you get All Elements from EHCache? there is not getAll().. only getAll(collection<keys>) - seesee

1 Answers

0
votes

I manage to achieve this by using:

Assume my key is a String:

List keys = Ehcache.getKeysWithExpiryCheck();
List<ABC> abcList = new ArrayList();

for(Object key = keys){
    String k = (String)((CacheKey) key).getKey();
    abcList.add(dao.get(k));
}

dao.get() will hit the cache first before database.

=) If anyone got any better solution please let me know.