简体   繁体   中英

Look up data stored in Cache in Mule

I got my end point/connectors working now part of my application I need to look up some configuration data from the database...

So as soon I start my application in mule I want data from the database and store it in memory and I want it to refresh the data every few minutes...

Then my main business logic can look up the data in Cache memory rather then hit the DB all the time...

You can make use of muleregistry to store information. Say if you want to refresh data every 10 mins. Below are the steps to be implemented. Step 1 and 2 are part of same flow.

1. Create database component inside poll component with frequency of 10 mins.

<poll doc:name="Poll">
      <fixed-frequency-scheduler frequency="10" timeUnit="MINUTES"/>
      <!--Place db component here-->
</poll>


2. Once step 1 is completed store the value retrieved in step 1 inside muleregistry. Below is example code to set key value using groovy.

 <scripting:component doc:name="Groovy">
                <scripting:script engine="Groovy"><![CDATA[muleContext.getRegistry().registerObject('Key1', new String('Value1')]]></scripting:script>
 </scripting:component>

3. Access value stored in muleregistry any where within application where mulecontext is available using MEL.


<set-variable variableName="keyVar" value="#[app.registry.get(&quot;Key1&quot;)]" mimeType="text/plain" doc:name="Variable"/>

Now the value from database is stored in flow variable KeyVar. Business logic always needs to read value from flow variable KeyVar which will be updated periodically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM