Contact Free trial Login

Set Up a Caching Strategy

You can create a caching strategy from a Cache scope properties panel or a Global Elements configuration in Anypoint Studio. After you create a strategy, a Cache component in your flow can reference it.

Follow these steps to configure a caching strategy:

  1. Open the caching strategy configuration window.

    You can open it from the Cache scope properties panel or the Caching Strategies option in the Global Elements tab within Studio:

    caching strategy configuration

  2. Define the Name of the caching strategy.

  3. Define the ObjectStore to use by selecting any of the following options:

    • Edit Inline
      Use this option to create an Object Store configuration specific for this caching strategy.

    • Global Reference
      Use this option either to select an existing Object Store, or to create a new global Object Store that can be referenced by this caching strategy and any other component in your application.

  4. Select a mechanism for generating a key used for storing events within the caching strategy:

    • Default

    • Key Expression

      A DataWeave expression (for example, keyGenerationExpression="#[vars.requestId]").

      Note that for two requests that are the same ("equal"), you need to generate the same key. Otherwise, you can get wrong results.

    • Key Generator

      Requires you to implement the com.mulesoft.mule.runtime.cache.api.key.MuleEventKeyGenerator interface.

  5. (Optional) Open the Advanced tab in the properties window to configure advanced settings:

    caching strategy advanced configuration

    • Select or create a Response Generator.

      Note that this step requires that you implement the com.mulesoft.mule.runtime.cache.api.response.ResponseGenerator interface.

    • Select the Event Copy Strategy:

      • Simple event copy strategy

        Data is immutable. This is the default value.

      • Serializable event copy strategy

        Data is mutable.

Example Caching Strategy

The following XML snippet shows the configuration of a caching strategy that defines a persistent Object Store to store the cached the responses. The caching strategy is then referenced by a Cache Scope:

<!-- Caching strategy definition -->
<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy" >
  <!-- Object Store defined for the caching strategy-->
    config-ref="ObjectStore_Config" />
<!-- Cache scope referencing the strategy-->
<ee:cache doc:name="Cache" cachingStrategy-ref="Caching_Strategy">
      <!-- Some processing logic to cache-->

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub