Mule Cache Module
Usage
This modules provides the ability to cache messages inside a Mule message flow. Here is a simple example:
">http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
</a> <a href="http://www.mulesoft.org/schema/mule/core">http://www.mulesoft.org/schema/mule/core</a> <a href="http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
">http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
</a> <a href="http://www.mulesoft.org/schema/mule/test">http://www.mulesoft.org/schema/mule/test</a> <a href="http://www.mulesoft.org/schema/mule/test/3.2/mule-test.xsd
">http://www.mulesoft.org/schema/mule/test/3.2/mule-test.xsd
</a> <a href="http://www.mulesoft.org/schema/mule/cache">http://www.mulesoft.org/schema/mule/cache</a> <a href="http://www.mulesoft.org/schema/mule/cache/3.2/mule-cache.xsd
">http://www.mulesoft.org/schema/mule/cache/3.2/mule-cache.xsd
</a> <a href="http://www.springmodules.org/schema/ehcache">http://www.springmodules.org/schema/ehcache</a> <a href="http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
">http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
</a> <a href="http://www.mulesoft.org/schema/mule/vm">http://www.mulesoft.org/schema/mule/vm</a> <a href="http://www.mulesoft.org/schema/mule/vm/3.2/mule-s.xsd">">http://www.mulesoft.org/schema/mule/vm/3.2/mule-s.xsd"></a> <spring:beans> <ehcache:config configlocation="classpath:ehcache.xml" failquietly="true" id="ehcache"> <spring:bean class="org.springmodules.cache.provider.ehcache.EhCacheCachingModel" id="cachingModel"> <spring:property name="cacheName" value="messages"> </spring:property> </spring:bean> <flow name="CachedFlow"> <inbound-endpoint address="vm://test" exchange-pattern="request-response"> <cache:cache-processor cache-ref="ehcache" cachingmodel-ref="cachingModel"> ... message processors you want cached ... </cache:cache-processor> </inbound-endpoint> </flow> </ehcache:config></spring:beans></mule>
This flow will cache incoming messages based on an MD5 hash of their payload. If your payload is a stream, it will be read into memory so it can be returned during future invocations.
You can control whether or not messages are cacheable and what key is used for the cache based on Mule expressions:
<flow name="CachedFlowWithExpressions"> <inbound-endpoint address="vm://test" exchange-pattern="request-response"> <cache:cache-processor cache-ref="ehcache" cacheableexpression="#[xpath://cacheable[text() = 'true']]" cachingmodel-ref="cachingModel" keygeneratorexpression="#[xpath://key]"> ... message processors you want cached ... </cache:cache-processor> </inbound-endpoint> </flow>
This will cache messages which match the following form and store the message in the cache with a key of '1'.
<message> <cacheable>true</cacheable> <key>1</key> </message>
Configuring your Cache
Underneath Spring Modules is used to configure caches. To find out more about configuring a particular cache facade, see: http://wiki.apache.org/jackrabbit/Clustering.
Using in Maven
To use in Maven, add the following dependency:
<dependency> <groupid>org.mule.modules</groupid> <artifactid>mule-module-cache</artifactid> <version>1.0-SNAPSHOT</version> </dependency>
With our library of Cloud Connectors and repeatable integration solutions, you can rapidly create connectivity either on premise or in the cloud.