如何在Mule中从内存存储中使缓存无效并清除缓存

时间:2015-03-08 09:06:06

标签: caching mule mule-studio

我有一个简单的怀疑...... 我有一个内存中缓存配置如下: -

<ee:object-store-caching-strategy name="cachingStrategy" doc:name="Caching Strategy">
<in-memory-store name="inMem" maxEntries="100" entryTTL="6800" expirationInterval="6800"/>
</ee:object-store-caching-strategy>

缓存工作正常,没有问题..但我想要的是使缓存无效..

我还创建了一个使所有缓存无效的流程,如下所示: -

<flow name="cacheinvalidate" doc:name="cacheinvalidate">
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8083/invalidate" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<ee:invalidate-cache cachingStrategy-ref="cachingStrategy"/>
<set-payload value="All cache invalidated" doc:name="Set Payload"/>
</flow>

但它不适用于内存商店 ..... 我得到以下例外: -

Message : Cannot not invalidate object store because it not a org.mule.api.store.ListableObjectStore (org.mule.api.cache.InvalidateCacheException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot not invalidate object store because it not a org.mule.api.store.ListableObjectStore (org.mule.api.cache.InvalidateCacheException)
com.mulesoft.mule.cache.ObjectStoreCachingStrategy:103 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/cache/InvalidateCacheException.html)
2. Cannot not invalidate object store because it not a org.mule.api.store.ListableObjectStore (org.mule.api.cache.InvalidateCacheException). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.cache.InvalidateCacheException: Cannot not invalidate object store because it not a org.mule.api.store.ListableObjectStore
at com.mulesoft.mule.cache.ObjectStoreCachingStrategy.invalidate(ObjectStoreCachingStrategy.java:103)
at com.mulesoft.mule.cache.InvalidateCacheMessageProcessor.process(InvalidateCacheMessageProcessor.java:24)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

我猜失效是通过迭代缓存中的键并删除条目来完成的,缓存实现必须是 ListableObjectStore (就像自定义对象存储一样),这似乎是对于内存商店​​,在这种情况下会丢失。

但我想知道,如果我使用内存存储,是否有任何方法可以使所有缓存无效并清除。

请建议,在这种情况下如何在内存中完成???

请注意我使用的是Mule 3.5和Mule企业<ee:cache>

3 个答案:

答案 0 :(得分:2)

尝试使用非持久性托管商店。

答案 1 :(得分:0)

是的,我得到的最终解决方案是使用非持久性托管商店: -

<ee:object-store-caching-strategy name="cachingStrategy" doc:name="cachingStrategy">
   <managed-store storeName="myNonPersistentManagedObjectStore" maxEntries="-1" entryTTL="20000" expirationInterval="5000"/>
</ee:object-store-caching-strategy>

答案 2 :(得分:0)

我们可以通过传递invalidate-key使缓存在内存中无效,如下所示:

<ee:cache doc:name="Cache" cachingStrategy-ref="Caching_Strategy_Database">
<ee:invalidate-key cachingStrategy-ref="Caching_Strategy_Database"/>