I know the cache topic has been discussed a lot here, but after reading the
related messages and Wonseok's blog(Thanks a lot.) I still have some
questions about how HardWeak/SoftWeak caches work, so here is my story.
I understand when I call em.persist(data) the data will be created and hold
by persistence context until em closes. The question is: when does it go to
shared cache? Does Toplink put the data into shared cache right after it is
persisted?
From TopLink Essentials JPA Extensions Reference I know HardWeak contains
two caches: LinkedList and HashMap. I was wondering when the LinkedList is
full, how does Toplink use the two caches? Does it just add the newly cached
data into the LinkedList and push out the top one into the HashMap? Or is
there any algorithm to decide whether data goes to LinkedList or HashMap?
Another question is about the HardWeak cahce. TopLink Reference says the
LinkedList holds hard references for cahced data. Does it mean thoese cache
will never be gc-ed even the system is short of memory until Toplink cleans
them after every 100nth access?
The next question is how I can tell how many data have been cached in
LinkedList or HashMap? I tried the following API:
((oracle.toplink.essentials.ejb.cmp3.EntityManager)em).getServerSession().getIdentityMapAccessor().printIdentityMaps()
and it does give me the data list, but I am not sure if it is a proper way.
By the way, above API works for java se. Could anybody tell me how to use it
in an EJB when the em is obtained by annotation?
I tried another way to count the HardWeak cahce and the sample is changed
from Wonseok's blog.
- 0 - Set cahce type HardWeak and size 50
- 1 - In first transaction, persist 100 data and close the em
- 2 - Update all 100 data in database by JDBC
- 3 - Open the second transaction call em.find to retrieve all the 100 data.
Count all unchanged data which should be from the cache.
But I am not sure if this is a valid test as well because of my first
question: If Toplink puts new cahced data into LinkedList and the old one
goes to HashMap which could be easily get gc-ed, then I will not get the
correct number.
Cheers,
Jason
--
View this message in context: http://www.nabble.com/Some-questions-about-HardWeak-SoftWeak-cache-tp17354187p17354187.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.