简体   繁体   English

Mule 4 缓存范围。 如何根据特定条件停止 mule 缓存

[英]Mule 4 Cache Scope. How to stop mule cache for based on certain conditions

I want to use cache in my mule app.我想在我的 mule 应用程序中使用缓存。 The flow is very simple, I am querying DB on the basis of email, and I want to store the result only if it returns some rows.流程很简单,我是根据email查询数据库,我只想在返回一些行时存储结果。 I referred to this question Mule Cache Scope How to invalidate mule cache for no payload of DB output but this solution is working for mule 3 only as Mule 4 uses repeatable streams .我提到了这个问题Mule Cache Scope How to invalidate mule cache for no payload of DB output但这个解决方案只适用于 mule 3,因为 Mule 4 使用可重复的流

I tried implementing the following workaround :我尝试实施以下解决方法:

  1. Wrap the cache scope inside a try scope.将缓存范围包装在 try 范围内。
  2. Raise an error when I do not want the cache to be stored.当我不想存储缓存时引发错误。
  3. On error continue error for only that error type仅针对该错误类型的错误继续错误

It executes the flow correctly, does not store the result in cache and also gives the successful response but it throws an error (probably in some async process) and I am seeing this in my logs它正确执行流程,不将结果存储在缓存中,也给出了成功的响应,但它抛出了一个错误(可能在某些异步进程中),我在我的日志中看到了这一点

    ERROR 2020-11-20 17:54:36,923 [[MuleRuntime].uber.03: cachingStrategy_null @302bcf75] [processor: testFlow1/processors/1/processors/0/processors/1; event: 594def80-2b2b-11eb-a1d0-a0d37a4d6fab] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
    ********************************************************************************
    Message               : The mapper returned a null value.
    Element               : testFlow1/processors/1/processors/0 @ test:test.xml:131 (Cache)
    Element DSL           : <ee:cache doc:name="Cache" doc:id="8c09cdc7-4fc9-4de1-a961-f74323f6ea7b" cachingStrategy-ref="Caching_Strategy">
                            <logger level="INFO" doc:name="Copy_of_Logger" doc:id="c539273d-7da2-4a20-bbdc-11f9fd4424cc" message="inside cache scope."></logger>
                            <ee:transform doc:name="Transform Message" doc:id="be16423b-c018-4949-b441-e81c6abc65ef">
                            <ee:message>
                            <ee:set-payload>%dw 2.0
    output application/json
    ---
    if(payload.store) {
        id: payload.id,
        time: now()
    }
    else {}</ee:set-payload>
                            </ee:message>
                            <ee:variables>
                            <ee:set-variable variableName="cacheEntry">%dw 2.0
    output application/java
...
Root Exception stack trace:
java.lang.NullPointerException: The mapper returned a null value.
    at java.util.Objects.requireNonNull(Objects.java:228)
    at reactor.core.* (4 elements filtered from stack; set debug level logging or '-Dmule.verbose.exceptions=true' for everything)(Unknown Source)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.mule.service.scheduler.internal.AbstractRunnableFutureDecorator.doRun(AbstractRunnableFutureDecorator.java:111)
    at org.mule.service.scheduler.internal.RunnableFutureDecorator.run(RunnableFutureDecorator.java:54)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

I am attaching a snippet of my flow too.我也附上了我的流程片段。

在此处输入图片说明

You can use the Invalidate Key operation to remove the key after it was added to the cache.将密钥添加到缓存后,您可以使用Invalidate Key操作将其删除。

It should added after the cache scope.它应该添加在缓存范围之后。

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

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