> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/virtual-environments/implementing-virtual-environments/configuring-a-virtual-environment-version/configuring-virtual-environment-replacements/replacement-caches.md).

# Replacement caches

## Introduction

Having [chosen to configure cache replacements for a virtual environment](/product-documentation/virtual-environments/implementing-virtual-environments/configuring-a-virtual-environment-version/configuring-virtual-environment-replacements.md#configuring-replacements-for-a-virtual-environment-version), a new replacement rule is displayed, ready for you to configure:

<figure><img src="/files/SElqyLExuqW0dtRMcruh" alt=""><figcaption></figcaption></figure>

Having defined the first rule, you can add more - you must create one replacement rule for every cache that you need to replace in every process flow that will run in this environment.

## Need to know

Please consider the [cache type](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape.md) used when replacing caches in [master process flows](/product-documentation/virtual-environments/implementing-virtual-environments/creating-a-master-process-flow.md).

<table data-full-width="true"><thead><tr><th width="141.7890625">Cache type</th><th width="159.76171875">Can be replaced in VE config?</th><th width="166.5625">Can be used in master process flows?</th><th>Cache key notes</th></tr></thead><tbody><tr><td><strong>Company</strong></td><td>Yes</td><td>Yes</td><td><p>We recommend that you always replace <code>company</code> caches in virtual environments, unless you have a good reason for not doing so. This ensures that caches are unique for each environment.</p><p>Keep in mind that cache keys are NOT replaced. Provided that you replace the <code>company</code> cache in each virtual environment, this is not an issue - the cache in each environment will be unique.</p><p>If, for some reason, you do not take this approach, please ensure that the given cache key in your master process flow utilises variables to ensure that it's unique at runtime - otherwise, cached data from one environment may overwrite data from another.</p></td></tr><tr><td><strong>Flow</strong></td><td>Yes</td><td>Yes</td><td><p>We recommend that you always replace <code>flow</code> caches in virtual environments, unless you have a good reason for not doing so. This ensures that caches are unique for each environment.</p><p>Keep in mind that cache keys are NOT replaced. Provided that you replace the <code>flow</code> cache in each virtual environment, this is not an issue - the cache in each environment will be unique.</p><p>If, for some reason, you do not take this approach, please ensure that the given cache key in your master process flow utilises variables to ensure that it's unique at runtime - otherwise, cached data from one environment may overwrite data from another. Please see <a href="/pages/GuXx8o7abzpLZrceEi5E#referencing-variables-for-unique-cache-keys">Referencing variables for unique cache keys</a> for more information.</p></td></tr><tr><td><strong>Flow run</strong></td><td>No</td><td>Yes</td><td>Behind the scenes, each cache key for a <code>flow run</code> cache is appended with a unique <code>flow run id</code> - although you never see this in the dashboard, it does mean that these caches will never clash between virtual environments.<br><br>However, if required, you can reference an environment variable in the cache key name, so the cache key is immediately identifiable for each virtual environment. please see <a href="/pages/GuXx8o7abzpLZrceEi5E#referencing-variables-for-unique-cache-keys">Referencing variables for unique cache keys</a> for more information.</td></tr></tbody></table>

{% hint style="info" %}
For more information on the different cache types, please refer to our [Add to cache](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape.md) documentation.
{% endhint %}

## Defining replacement rules for a cache

{% stepper %}
{% step %}
**Select the required ORIGINAL cache**

Use the `original` dropdown list to select the first company cache in a 'master' process flow that must be replaced when this process flow runs in the given virtual environment - for example:

<figure><img src="/files/hT8Vz4ziDk7KuCAtI82z" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
As you work through your replacement configuration, it's helpful to view related ['master' process flows](/product-documentation/virtual-environments/implementing-virtual-environments/creating-a-master-process-flow.md) in another browser tab. You can duplicate a Patchworks browser tab and navigate to a different page whenever needed.
{% endhint %}
{% endstep %}

{% step %}
**Select the required REPLACEMENT cache**

Use the `replacement` dropdown list to select the replacement cache that must be used when this process flow runs in the given virtual environment - for example:

<figure><img src="/files/518odhAt3S6zTmQq2d30" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Confirm your selections**

Click the `create` button (associated with this replacement rule) to confirm your selections:

<figure><img src="/files/bhV2bWvNeGQsrRLI4gGh" alt=""><figcaption></figcaption></figure>

The rule is added:

<figure><img src="/files/9Uqzi5LRB9qgjNGxiBvq" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Once a rule is confirmed, it can't be edited. If you need to change a replacement rule, use the 'trash' icon to remove it and add a new one.
{% endhint %}
{% endstep %}

{% step %}
**Add more replacement rules for caches**

To add another replacement rule for a cache, click the top-right `create` button:

<figure><img src="/files/M7SqVwBcwloASOQU54x2" alt=""><figcaption></figcaption></figure>

Update the new rule as required, then click the associated `create` button to confirm your selections:

<figure><img src="/files/6rH0c2tB2WHwQzpX2N0B" alt=""><figcaption></figcaption></figure>

Repeat as many times as needed to define all required cache replacements for all process flows that will be running in this virtual environment.

{% hint style="info" %}
If you don't want to define ALL cache replacements now, that's OK. For example, you might choose to add the minimum number of replacements needed for [testing](/product-documentation/virtual-environments/implementing-virtual-environments/testing-a-process-flow-against-a-virtual-environment.md), then define remaining rules (in a [new draft](/product-documentation/virtual-environments/implementing-virtual-environments/configuring-a-virtual-environment-version/understanding-virtual-environment-versions.md)) later, after initial testing is complete.
{% endhint %}
{% endstep %}
{% endstepper %}
