---
schema_version: "1"
id: 65701ecf23a39e8e3d3bb0addc1de83451be85744683bd31efdd87d8298e6c2c
title: Invalidate Cache Entries
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.6/cache-scope-invalidate.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.6/cache-scope-invalidate
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 521c8f24a08ffa9e32285513741bec76f12b61ce176b01fa40a05a04fa534a78
description: MuleSoft Documentation Site
release: "4.6"
latest: false
---
---
product: Mule Runtime
version: 4.6
---

# Invalidate Cache Entries

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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.

> [!WARNING] Do not specify an Invalidate Key or Invalidate Cache component inside a Cache scope if
> they reference the same caching strategy unless the caching strategy disables synchronized access.
> Otherwise, the application will stop responding when it tries to invalidate the locked cache.

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

```xml
<!-- 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

```xml
<!-- 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](https://docs.mulesoft.com/mule-runtime/4.6/cache-scope-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

```xml
<!-- 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>
```

## See Also

- [Configure the Cache Scope](https://docs.mulesoft.com/mule-runtime/4.6/cache-scope-to-configure)

- [Set Up a Caching Strategy](https://docs.mulesoft.com/mule-runtime/4.6/cache-scope-strategy)

- [Object Store Configuration](https://docs.mulesoft.com/mule-runtime/4.6/mule-object-stores#object-store-config)

- [Object Store Reference](https://docs.mulesoft.com/object-store-connector/latest/object-store-connector-reference#objectStore)
