繁体   English   中英

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

[英]Look up data stored in Cache in Mule

我的端点/连接器现在正在我的应用程序中工作,我需要从数据库中查找一些配置数据...

因此,一旦我在m子中启动我的应用程序,我就希望从数据库中获取数据并将其存储在内存中,并且希望它每隔几分钟刷新一次数据...

然后,我的主要业务逻辑可以在缓存中查找数据,而不是一直访问数据库。

您可以使用muleregistry来存储信息。 假设您要每10分钟刷新一次数据。 以下是要执行的步骤。 步骤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"/>

现在,数据库中的值存储在流变量KeyVar中。 业务逻辑始终需要从流量变量KeyVar中读取值,该值将定期更新。

暂无
暂无

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

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