I am using ehcache 1.2.3. Since the cache size is specified in terms of "elements", the memory which the cache occupies may vary greatly (the ehcache is used together with hibernate and holds also the standard query cache where the queries return resultsets of size which may vary). My question is: what happens if JVM gets low on memory. My impression from reading the changelog of ehcache is that initially it was using soft references, but since java 1.4 was cleaning them agressively, the soft references were eventually dropped. Thus if the cache gets too big, I would just get OutOfMemoryError? Nothing in Ehcache which tries to prevent it?
You're correct in that if you want to create an OOM with ehcache you can do that. Have you had a look at the sizing options, though like maxEntriesLocalHeap / maxBytesLocalHeap. Using those you can effectively prevent caches to use more than an allocated amount of memory.
See for example http://ehcache.org/documentation/configuration/cache-size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With