简体   繁体   English

在Mule中查找存储在缓存中的数据

[英]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... 因此,一旦我在m子中启动我的应用程序,我就希望从数据库中获取数据并将其存储在内存中,并且希望它每隔几分钟刷新一次数据...

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. 您可以使用muleregistry来存储信息。 Say if you want to refresh data every 10 mins. 假设您要每10分钟刷新一次数据。 Below are the steps to be implemented. 以下是要执行的步骤。 Step 1 and 2 are part of same flow. 步骤1和2是同一流程的一部分。

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. 现在,数据库中的值存储在流变量KeyVar中。 Business logic always needs to read value from flow variable KeyVar which will be updated periodically. 业务逻辑始终需要从流量变量KeyVar中读取值,该值将定期更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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