CachePage edited by Claus IbsenChanges (3)
Full ContentCache ComponentAvailable 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, used the processors defined for the cache component. Maven users will need to add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-cache</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
Cache ConsumerReceiving 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 ADD/UPDATE/DELETE/DELETEALL). Upon such an activity taking place
Cache ProcessorsThere are a set of nice processors with the ability to perform cache lookups and selectively replace payload content at the
Cache Usage SamplesExample 1: Configuring the cachefrom("cache://MyApplicationCache" + "?maxElementsInMemory=1000" + "&memoryStoreEvictionPolicy=" + "MemoryStoreEvictionPolicy.LFU" + "&overflowToDisk=true" + "&eternal=true" + "&timeToLiveSeconds=300" + "&timeToIdleSeconds=true" + "&diskPersistent=true" + "&diskExpiryThreadIntervalSeconds=300") Example 2: Adding keys to the cacheRouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("ADD")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; Example 2: Updating existing keys in a cacheRouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("UPDATE")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; Example 3: Deleting existing keys in a cacheRouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("DELETE")) .setHeader("CACHE_KEY", constant("Ralph_Waldo_Emerson")) .to("cache://TestCache1") } }; Example 4: Deleting all existing keys in a cacheRouteBuilder builder = new RouteBuilder() { public void configure() { from("direct:start") .setHeader("CACHE_OPERATION", constant("DELETEALL")) .to("cache://TestCache1"); } }; Example 5: Notifying any changes registering in a Cache to Processors and other ProducersRouteBuilder builder = new RouteBuilder() { public void configure() { from("cache://TestCache1") .process(new Processor() { public void process(Exchange exchange) throws Exception { String operation = (String) exchange.getIn().getHeader("CACHE_OPERATION"); String key = (String) exchange.getIn().getHeader("CACHE_KEY"); Object body = exchange.getIn().getBody(); // Do something } }) } }; Example 6: Using Processors to selectively replace payload with cache valuesRouteBuilder builder = new RouteBuilder() { public void configure() { //Message Body Replacer from("cache://TestCache1") .filter(header("CACHE_KEY").isEqualTo("greeting")) .process(new CacheBasedMessageBodyReplacer("cache://TestCache1","farewell")) .to("direct:next"); //Message Token replacer from("cache://TestCache1") .filter(header("CACHE_KEY").isEqualTo("quote")) .process(new CacheBasedTokenReplacer("cache://TestCache1","novel","#novel#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","author","#author#")) .process(new CacheBasedTokenReplacer("cache://TestCache1","number","#number#")) .to("direct:next"); //Message XPath replacer from("cache://TestCache1"). .filter(header("CACHE_KEY").isEqualTo("XML_FRAGMENT")) .process(new CacheBasedXPathReplacer("cache://TestCache1","book1","/books/book1")) .process (new CacheBasedXPathReplacer("cache://TestCache1","book2","/books/book2")) .to("direct:next"); } };
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > Cache confluence
- [CONF] Apache Camel > Cache confluence
- [CONF] Apache Camel > Cache confluence
- [CONF] Apache Camel > Cache confluence