Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the asciidoc in the repository: https://github.com/apache/camel/blob/master/README.md https://github.com/apache/camel/blob/master/components/readme.adoc
This component is deprecated. As of Camel 2.18.0 You should use Ehcache.
Available as of Camel 2.1
The cache component enables you to perform caching operations using EHCache as the Cache Implementation. The cache itself is created on demand or if a cache of that name already exists then it is simply utilized with its original settings.
This component supports producer and event based consumer endpoints.
The Cache consumer is an event based consumer and can be used to listen and respond to specific cache activities. If you need to perform selections from a pre-existing cache, use the processors defined for the cache component.
Maven users will need to add the following dependency to their
You can append query options to the URI in the following format,
Cache Component options
Sending/Receiving Messages to/from the cache
Message Headers up to Camel 2.7
Message Headers Camel 2.8+
Header changes in Camel 2.8
The header names and supported values have changed to be prefixed with 'CamelCache' and use mixed case. This makes them easier to identify and keep separate from other headers. The CacheConstants variable names remain unchanged, just their values have been changed. Also, these headers are now removed from the exchange after the cache operation is performed.
Sending data to the cache involves the ability to direct payloads in exchanges to be stored in a pre-existing or created-on-demand cache. The mechanics of doing this involve
Receiving data from the cache involves the ability of the CacheConsumer to listen on a pre-existing or created-on-demand Cache using an event Listener and receive automatic notifications when any cache activity take place (i.e CamelCacheGet/CamelCacheUpdate/CamelCacheDelete/CamelCacheDeleteAll). Upon such an activity taking place
There are a set of nice processors with the ability to perform cache lookups and selectively replace payload content at the
Cache Usage Samples
Example 1: Configuring the cache
Example 2: Adding keys to the cache
Example 2: Updating existing keys in a cache
Example 3: Deleting existing keys in a cache
Example 4: Deleting all existing keys in a cache
Example 5: Notifying any changes registering in a Cache to Processors and other Producers
Example 6: Using Processors to selectively replace payload with cache values
Example 7: Getting an entry from the Cache
Example 8: Checking for an entry in the Cache
Note: The CHECK command tests existence of an entry in the cache but doesn't place a message in the body.
Management of EHCache
Here's a snippet on how to expose them via JMX in a Spring application context:
Of course you can do the same thing in straight Java:
You can get cache hits, misses, in-memory hits, disk hits, size stats this way. You can also change CacheConfiguration parameters on the fly.
Cache replication Camel 2.8+
The Camel Cache component is able to distribute a cache across server nodes using several different replication mechanisms including: RMI, JGroups, JMS and Cache Server.
There are two different ways to make it work:
1. You can configure
2. You can configure these three options:
Configuring Camel Cache replication using the first option is a bit of hard work as you have to configure all caches separately. So in a situation when the all names of caches are not known, using
The second option is much better when you want to use many different caches as you do not need to define options per cache. This is because replication options are set per
It might be useful to read the EHCache manual to get a better understanding of the Camel Cache replication mechanism.
Example: JMS cache replication
JMS replication is the most powerful and secured replication method. Used together with Camel Cache replication makes it also rather simple.