Bozho
Bozho

Reputation: 597106

What is the difference between "cache misses" and "in memory cache misses" in 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.

Upvotes: 7

Views: 1240

Answers (2)

laher
laher

Reputation: 9110

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

Upvotes: 1

Chandra
Chandra

Reputation: 333

I believe you are using ehcache 2.5+ . If you have cacheconfiguration with diskpersistance to true ( though overflowtodisk is false) , it writes to disk. So there could be diskhits as well? You can view them in the Statistics. do you have diskpersistance as true? Please post your cache configuration

Upvotes: 0

Related Questions