Contact Us 1-800-596-4880

Invalidate Cache Entries

This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

Invalidate cache entries when you want the Cache Scope to recalculate the value for those cache entries.

You can invalidate a cache key or a complete cache by using the Invalidate Key and Invalidate Cache components, respectively. Alternatively, you can configure the caching strategy to invalidate entries automatically based on time.

Invalidate a Cache Key

Configure the Invalidate Key component in your application flow to invalidate a cache key in the referenced caching strategy.

Configure the Invalidate Key Component

Follow these steps to configure the Invalidate Key component:

  1. In Anypoint Studio, drag the Invalidate Key component to your flow.

  2. Click the Invalidate Key component in your flow to open its properties.

  3. Specify the Caching Strategy where the cache key to invalidate is stored.

  4. Optionally, select the method for calculating the cache key.

Example Invalidate Cache Key Configuration

<!-- Caching strategy configuration -->
<ee:object-store-caching-strategy name="myCachingStrategy" keyGenerationExpression="#[payload.key]" />

<flow name="cacheFlow">
  <ee:cache cachingStrategy-ref="myCachingStrategy">
      <!-- Processing logic inside the Cache Scope -->
  </ee:cache>
</flow>

<flow name="invalidateItemFlow">
  <!-- Invalidate Key component configuration -->
  <ee:invalidate-key cachingStrategy-ref="myCachingStrategy" keyGenerationExpression="#[payload.key]" />
</flow>

Invalidate a Complete Cache

Configure the Invalidate Cache component in your application flow to invalidate the complete cache in the referenced caching strategy.

Configure the Invalidate Cache Component

Follow these steps to configure the Invalidate Cache component:

  1. In Anypoint Studio, drag the Invalidate Cache component to your flow.

  2. Click the Invalidate Cache component in your flow to open its properties.

  3. Specify the Caching Strategy to invalidate.

Example Invalidate a Complete Cache Configuration

<!-- Caching strategy configuration -->
<ee:object-store-caching-strategy name="myCachingStrategy" />

<flow name="cacheFlow">
  <ee:cache cachingStrategy-ref="myCachingStrategy">
      <!-- Processing logic inside the Cache Scope -->
  </ee:cache>
</flow>

<flow name="invalidateCompleteCacheFlow">
  <!-- Invalidate Cache component configuration -->
  <ee:invalidate-cache cachingStrategy-ref="myCachingStrategy" />
</flow>

Automatic Invalidation

When you configure the caching strategy, you can configure a custom object store and set the time to live (entryTtl) value to make stored cache keys expire over time.

Configure the Object Store in Your Caching Strategy

The following steps show how to configure the object store in your caching strategy to invalidate cache keys automatically after a set time:

  1. Follow the steps in Set Up a Caching Strategy.

  2. When configuring the object store for the strategy, set a value for Entry ttl.

    This value represents the time after which the cache entry expires.

  3. Complete the object store configuration.

Example Automatic Invalidation Configuration

<!-- Object Store configuration-->
<os:config name="ObjectStore_Config"/>
<!-- Caching Strategy configuration-->
<ee:object-store-caching-strategy name="Caching_Strategy">
  <!-- Object Store defined for the caching strategy -->
  <os:private-object-store
    alias="CachingStrategy_ObjectStore"
    maxEntries="100"
    entryTtl="10"
    expirationInterval="5"
    config-ref="ObjectStore_Config"/>
</ee:object-store-caching-strategy>