Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "cache misses" and "in memory cache misses" in Ehcache?

Tags:

java

ehcache

I'm looking in the EhCache statistics, I see these figures:

CacheMisses: 75977
CacheHits: 38151

InMemoryCacheMisses: 4843
InMemoryCacheHits: 38151

"memory" is the only store - no off-heap and no disk storage (overflowToDisk="false", diskPersistent="false"). So what does these two mean? I would expect them to be the same (the hits are the same), but the misses differ greatly.

like image 403
Bozho Avatar asked Aug 08 '12 22:08

Bozho


1 Answers

Do you have some null-valued Elements in your cache? (Ehcache allows you to store Elements with null values, but I'm not sure if there's any constraints surrounding that).

Looking at the code for Cache.searchInStoreWithStats(Object key) in version 2.5.3, it seems that there is a bug there:

  • The test determining whether to increment inMemoryMisses uses a containsKey() derivative,
  • whereas the test for incrementing cacheMisses null-checks against the result of a get() derivative.

So, each time you search for a key which exists in the InMemoryStore but has a null value, it will increment cacheMisses but not inMemoryMisses.

So, I might be completely off, but it smells right to me. What do you think?

Edit: I've realised my interpretation was wrong - the Element can't be null, (but its 'value' can be null). I'll leave this answer here anyway incase it triggers any other ideas

like image 54
laher Avatar answered Oct 16 '22 14:10

laher