Mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject [HEADS UP] - Camel uses soft reference cache now
Date Mon, 02 May 2011 14:00:33 GMT

Just a heads up on
I have committed that to trunk in SVN rev: 1098574.

The change will use a SoftReference cache for the following internal
caches in camel-core
- endpoint cache
- producer cache
- consumer cache
- bean info cache
- property editor type converter (miss cache)

So what we will have in org.apache.camel.util is 2 kind of LRU caches
- LRUCache = uses strong reference cache and ensure data in cache is
kept until explicit removed
- LRUSoftCache = uses soft reference cache, will allows JVM to GC
values from the cache, in case it runs low on memory

There is an LRUSoftCacheTest unit test which demonstrates the
situation with the JVM running out of memory.
If you change the test to use the LRUCache then you will quickly run
out of memory.

So what the LRUSoftCache offers over the LRUCache is that in case the
JVM is running low on memory, it allows the JVM to claim
the memory for the values in the cache. Its kinda like auto-shrink if
we run low on memory. Since its a cache, then we will just re-create
the value in case there was a cache miss. Also the max cache size is
of course still in-play. So if the cache has a limit of 1000, then
at most 1000 values is stored in the cache. And its LRU based, so we
prefer to keep the most used.

I gave the full project a test and didn't encounter any issues due
this change. But in case you discover some odd behavior after this
change, then let us know.
Also if you are keen on cache code, then take a look and review the
LRUSoftCache source code.

I will add some JMX stats for the cache, so we at runtime can see some
stats such as cache hit/miss etc.

You can read about soft references here (notice it indicate its for
memory sensitive caches)

If you wonder why we are not using weak references instead, then
that's actually a poor choice for caches. See for example what Google

Claus Ibsen
CamelOne 2011:
Twitter: davsclaus
Author of Camel in Action:

View raw message