简体   繁体   中英

How to invalidate and clear cache from in-memory-store in Mule

I have a simple doubt ... I have a in-memory cache configuration as following :-

<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>

The cache is working fine with no issue .. But what I want is to invalidate the cache ..

I have also created a flow for invalidating all the cache as follow :-

<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>

But it's not working in the case of in-memory-store ..... I am getting following exception :-

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)

I guess the invalidation is done by iterating the keys in the cache and deleting the entries, and the cache implementation must be a ListableObjectStore ( like in case of custom object-store ), which seems to be missing in this case for in-memory-store.

But I like to know if there any way that I can invalidate and clear all the cache if I use in-memory-store.

Please suggest, how it can be done here in this case of in-memory-store ???

Please note that I am using Mule 3.5 and Mule enterprise <ee:cache>

尝试使用非持久性托管存储。

Yes, the final solution I got is using a non-persistent managed-store :-

<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>

We can invalidate the cache in-memory-store by passing invalidate-key as given below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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