简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM