Mule Cache Scope How to invalidate mule cache for no payload of DB output

人盡茶涼 提交于 2021-01-28 09:47:49

问题


We would like to use DB query inside mule cache scope.

Wants to store the output of DB query in cache to save DB query trip.

If the DB query doesn't give any output or payload is empty, we dont want to save in mule cache.

How to invalidate the cache of the empty payload entries ?

thank you.


回答1:


The answer to this is in mule forum, https://forums.mulesoft.com/questions/84675/mule-cache-scope-how-to-invalidate-mule-cache-for.html

 <ee:cache cachingStrategy-ref="Caching_Strategy" filterExpression="#
   [payload 
      != 'testData']" doc:name="Cache">
         <db:select config-ref="DBConfig" fetchSize="100" 
            doc:name="Database">
             <db:dynamic-query><![CDATA[select * from STUDENT where 
                 student_id = 'TEST']]></db:dynamic-query>
                    </db:select>
                      <choice doc:name="Choice">
                          <when expression="#[message.payload.size() == 0]">
                 <logger message="Payload is empty" level="INFO" 
                   doc:name="Logger"/>
                 <dw:transform-message doc:name="Transform Message">
                     <dw:set-payload><![CDATA[%dw 1.0
                      %output application/json
                        ---
                    payload]]></dw:set-payload>
                 </dw:transform-message>
             </when>
             <otherwise>
                 <object-to-string-transformer doc:name="Object to String"/>
           </otherwise>
       </choice>
       <logger message="After Choice" level="INFO" doc:name="Logger"/>
   </ee:cache>


来源:https://stackoverflow.com/questions/48229288/mule-cache-scope-how-to-invalidate-mule-cache-for-no-payload-of-db-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!