Contact Free trial Login

Invalidate Cache Entries

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>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub