Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ehcache low memory behaviour

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?

like image 622
John Donn Avatar asked Nov 13 '22 03:11

John Donn


1 Answers

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

like image 141
moodywoody Avatar answered Nov 16 '22 04:11

moodywoody