This documentation is for WSO2 Enterprise Service Bus version 4.7.0 . View documentation for the latest release.

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


  1. In this example, the first message is sent to the endpoint specified as cache is not hit. The response will come to the Cache Mediator inside the out mediator, which caches the response. The second similar message will match the cache and the response will be directly fetched from the cache and sent to the requester. This happens because no onCacheHit sequence is defined.

    Code Block
    <sequence name="SEQ_CACHE">
        <cache scope="per-host"
          <implementation type="memory" maxSize="100"/>
            <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
        <cache scope="per-host" collector="true"/>
  2. According to this example configuration, if you define a cache collector using the cache mediator in the in sequence, you need to add the RESPONSE property to consider the message as a response message.

    Code Block
    <api xmlns="" name="cacheAPI" context="/cache">
       <resource methods="POST GET" uri-template="/headerapi/*">
    		<cache collector="false" timeout="5000">
    			<protocol type="HTTP">
    				<methods>GET, POST</methods>
    				<hashGenerator>org.      <inSequence>
             <cache id="cache-sample" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.HttpRequestHashGenerator</hashGenerator>
    				DOMHASHGenerator" timeout="5000">
                <implementation type="memory" maxSize="1000"/>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
    		         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
                <source type="inline" clone="true">
    				               <ax21:newvalue 					xmlns:ax21="http://services.samples/xsd">testsamplevalue 				               </ax21:newvalue>
    				            <target xmlns:ax21="http://services.samples/xsd" 				xmlns:ns="http://services.samples" action="sibling" xpath="//ns:getQuoteResponse/ns:return/ax21:volume"/>
    			<cache          <cache scope="per-host" collector="true"/>

See also Sample 420: Simple Cache Implemented on ESB for the Actual Service.