...
Cache Mediator Attributes:
- id - The Cache Mediator must be specified with an
id
and two Specify an ID for the Cache Mediator to have two instances with the same sameid
that that correlates the response message into the cache for the request message hash, when you have multiple cache mediators within your Synapse configuration. - timeout - Optional attribute, which specifies the valid duration for cached elements. The scope defines if the mediator instances share a common cache per every host instance or per every Cache Mediator pair (i.e.
id
) instance. - collector
- true - The
collector
attribute's value astrue
specifies that the mediator instance is a response collection instance. - false - The
collector
attribute's value asfalse
specifies that it's a cache serving instance.
- true - The
- maxMessageSize - An optional attribute, which specifies the maximum size of a message to be cached in bytes and defaults to unlimited.
- implementation - The attribute, which defines if the cache is disk or memory based.
- maxSize - The attribute, which defines the maximum number of elements to be cached.
...
Cache Mediator General Options
Anchor | ||||
---|---|---|---|---|
|
- Cache Id - Id for cache Specify an ID for the Cache Mediator to have two instances with the same
id
that correlates the response message into the cache for the request message hash, when you have multiple cache mediators within your Synapse configuration.
Info | ||
---|---|---|
| ||
You should have the same id for a cache mediator instance in incoming path and the corresponding mediator instance in outgoing message path. |
...
Info | ||
---|---|---|
| ||
You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window. |
...
Example
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 | ||||
---|---|---|---|---|
| ||||
<definitions xmlns="http://ws.apache.org/ns/synapse">
<in>
<cache timeout="20" scope="per-host" collector="false"
hashGenerator="org.wso2.caching.digest.DOMHASHGenerator">
<implementation type="memory" maxSize="100"/>
</cache>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</in>
<out>
<cache collector="true"/>
<send/>
</out>
</definitions> |
...
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="http://ws.apache.org/ns/synapse" name="cacheAPI" context="/cache">
<resource methods="POST GET" uri-template="/headerapi/*">
<inSequence>
<cache id="cache-sample" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator" timeout="5000">
<implementation type="memory" maxSize="1000"/>
</cache>
<call>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</call>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<enrich>
<source type="inline" clone="true">
<ax21:newvalue xmlns:ax21="http://services.samples/xsd">testsamplevalue </ax21:newvalue>
</source>
<target xmlns:ax21="http://services.samples/xsd" xmlns:ns="http://services.samples" action="sibling" xpath="//ns:getQuoteResponse/ns:return/ax21:volume"/>
</enrich>
<cache scope="per-host" collector="true"/>
<respond/>
</inSequence>
</resource>
</api> |
Excerpt | |
---|---|
hidden | true
Description of the Cache Mediator in WSO2 ESB.