I am using Anypoint Studio 6.1 and Mule 3.8.1 and have a mule managed store Caching Strategy that uses the default Event Key generation.
How can I get the value of this key in a flow? Where is it stored?
Thanks
By default the generator provides SHA 256 hash
as a key if you don't provide a key generator expression in your cache.
ref:- https://github.com/mulesoft/mule/blob/mule-3.x/core/src/main/java/org/mule/keygenerator/SHA256MuleEventKeyGenerator.java
This generators computes a SHA 256 hash
of the current message bytes payload.
You can use the following example to get the list of cache key of your flow:-
<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>
<flow name="keylist" doc:name="keylist">
<http:listener config-ref="HTTP_Listener_Configuration" path="/getkeyvalue" doc:name="HTTP"/>
<scripting:component doc:name="Initialise Database">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[
def keyValues = [];
for(a=0;a<muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().size();a++)
{
keyValues = muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().get(a);
}
if(keyValues.isEmpty())
{
return "Key is either null or expired !!!";
}
else
{
return "KeysList " + muleContext.getRegistry().lookupObject("cachingStrategy").getStore().allKeys().toString();
}
]]></scripting:text>
</scripting:script>
</scripting:component>
</flow>
Whenever you put some message in your cache, using the above flow you can get all the list of the default cache keys values which the cache scope provide as SHA 256 hash
as default