> 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/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/appending-data-to-a-cache.md).

# Appending data to a cache

## Introduction

We've already noted how the [add to cache](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape.md) shape can be added to a process flow to cache the entire payload at a given point in the flow. The default behaviour is that when a process flow runs and hits an **add to cache** shape, any existing data associated with that cache is overwritten with a new payload from the new run.

However, it is possible to **append** data to a cache, so each time the process flow runs and the **add to cache** shape is reached, the current cache is appended to the existing cache. This works for any cache type (**flow**, **flow run**, and **company**).

## Need to know

* **Paginated data**. If your connection shape receives paginated data, it's important to understand how the **save all pages** option works in conjunction with **append**. For more information please see our [cache pagination options page](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/cache-pagination-options.md).
* **Cache size**. Theoretically, if a cache is set to append data and then runs on a regular basis indefinitely, the cache size may grow to an unmanageable size. With this in mind, a limit is in place to ensure that a single cache cannot exceed 50MB.
* **Append data format**. Appending cached data is supported for JSON only.
* **Shared caches.** The append to cache operation is not atomic - as such we advise against multiple process flows attempting to update the same cache at the same time.

## Using the append option

To use the **append** option, follow the steps below.

**Step 1**\
[Drop an add to cache shape into your process flow in the normal way](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape.md#adding-an-add-to-cache-shape-to-a-process-flow) - create your cache, then select it and add your cache key.

**Step 2**\
Ensure that the save all pages option is set as needed. For more information about how this option affects appended data please see our [cache pagination options page](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/cache-pagination-options.md).

**Step 3**\
Enable the **append** option:

<div align="left"><figure><img src="/files/TEdYWTxIFn6hiPT87Z43" alt="" width="351"><figcaption></figcaption></figure></div>

**Step 4**\
A **path to append to** field is displayed:

<div align="left"><figure><img src="/files/BIGTgjNOyVF0dsxvuNo9" alt="" width="351"><figcaption></figcaption></figure></div>

Here, you need to consider the structure of the payload that you're passing in and specify a path that ensures that each new payload is appended in the right place.

<details>

<summary><img src="/files/VDlwYFR9Br2ScHUDewYv" alt="" data-size="line"> Example</summary>

Consider the payload below:

{% code lineNumbers="true" %}

```json
{
  "orders": [
    {
      "id": 1,
      "customer": {
        "email": "joe.bloggs@wearepatchworks.com"
      }
    },
    {
      "id": 2,
      "customer": {
        "email": "jane.bloggs@wearepatchworks.com"
      }
    }
  ]
}
```

{% endcode %}

In this case, we want to append new data to the `orders` object, so our path to append to would be defined as `orders`. The first time the cache is updated, the payload would be:

{% code overflow="wrap" lineNumbers="true" %}

```json
[{"orders":[{"id":1,"customer":{"email":"joe.bloggs@wearepatchworks.com"}},{"id":2,"customer":{"email":"jane.bloggs@wearepatchworks.com"}}]}]
```

{% endcode %}

The next time the payload is appended, it would be in the form below:

{% code overflow="wrap" lineNumbers="true" %}

```json
{"0":{"orders":[{"id":1,"customer":{"email":"joe.bloggs@wearepatchworks.com"}},{"id":2,"customer":{"email":"jane.bloggs@wearepatchworks.com"}}]},"orders":[{"orders":[{"id":3,"customer":{"email":"dave.bowie@wearepatchworks.com"}},{"id":4,"customer":{"email":"michael.jagger@wearepatchworks.com"}}]}]}
```

{% endcode %}

</details>

{% hint style="info" %}
If required, [flow variables](/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables.md) can be specified here.
{% endhint %}

**Step 5**\
Save the shape. Next time the process flow runs the data will be cached and appended.

## Viewing the appended cache

If you choose to view the payload for an **add to cache** shape, the payload will always show data from the latest run - for example:

<div align="left"><figure><img src="/files/EZojeR19uXaigqOzODQf" alt=""><figcaption></figcaption></figure></div>

However, when you add a load from cache shape, the payload will show ALL appended data so far - for example:

<figure><img src="/files/2tFg1chP1q7G1YWmv8iW" alt=""><figcaption></figcaption></figure>
