# Cache pagination options

## Introduction

When you drop an [add to cache shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape.md) into a process flow, there are two options that you should consider if your selected endpoint paginates the data that is received OR you generate multiple payloads in some other way (for example, via the [flow control](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape.md) shape). These options are: `save all pages` and `append`.

<div align="left"><figure><img src="/files/q796pf5q4XYtIb3nBTtK" alt="" width="355"><figcaption></figcaption></figure></div>

Together, these two options determine how multiple payloads are cached, so it's important to understand the implications of each.

{% hint style="info" %}
On this page we focus on paginated data however, the same principles apply whenever multiple payloads are cached, irrespective of whether those payloads are generated via pagination or some other means (for example, via the [flow control](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape.md) shape).
{% endhint %}

## Save all pages

When paginated data is pulled from a [connection shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape.md), a payload is created for each page - you can see these in the [run log payload tab](/product-documentation/process-flows/error-reporting-and-exception-handling/real-time-run-logs.md#payloads):

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

If you are caching paginated data and choose to toggle the `save all pages` option to `on`, the payload for each page is saved with its page number and a `unique key`. For example:

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

The `unique key` is generated dynamically, by adding the page number to your specified cache key. If the cache is a `flow run` type, the `unique key` will also incorporate the `flow run id`.

{% hint style="warning" %}
It's important to note that every time a connection shape pulls paginated data, page numbers reset to 1.
{% endhint %}

## Append

When the **append** option is toggled ON, incoming payloads are appended to cache keys.  How this works depends on the **save all pages** option:

<table><thead><tr><th width="179">Save all pages<select><option value="IpYg94QqUbeW" label="OFF" color="blue"></option><option value="8FrwXU3PGUr5" label="ON" color="blue"></option></select></th><th width="171">Append to cache<select><option value="7AJHUuEOr98a" label="ON" color="blue"></option><option value="wBWZjpMQuf0j" label="OFF" color="blue"></option></select></th><th>Cache behaviour</th></tr></thead><tbody><tr><td><span data-option="IpYg94QqUbeW">OFF</span></td><td><span data-option="wBWZjpMQuf0j">OFF</span></td><td>The given <code>cache key</code> is overwritten each time a payload is cached. As such, the <code>cache key</code> will only ever include data from the LAST payload received.</td></tr><tr><td><span data-option="8FrwXU3PGUr5">ON</span></td><td><span data-option="wBWZjpMQuf0j">OFF</span></td><td><p>The first time that multiple payloads are received, each one is saved to its own <code>unique key</code>, against your specified <code>cache key</code>. </p><p></p><p>Next time the cache receives data, any existing <code>unique keys</code> associated with your specified <code>cache key</code> are overwritten. Additional <code>unique keys</code> are created for new payloads/pages as needed). </p><p></p><p>As such, each <code>unique key</code> will only ever contain the latest data for the correlating payload/page number.</p></td></tr><tr><td><span data-option="IpYg94QqUbeW">OFF</span></td><td><span data-option="7AJHUuEOr98a">ON</span></td><td>Each payload is appended to your specified <code>cache key</code>. As such, data in the cache key continues to grow with each data pull - nothing is overwritten.</td></tr><tr><td><span data-option="8FrwXU3PGUr5">ON</span></td><td><span data-option="7AJHUuEOr98a">ON</span></td><td><p>The first time that multiple payloads are received, each one is saved to its own <code>unique key</code>, against your specified <code>cache key</code>. </p><p></p><p>Next time the cache receives data, any existing <code>unique keys</code> associated with your specified <code>cache key</code> are appended with the latest data from correlating payload/page numbers. Additional <code>unique keys</code> are created for new payloads/pages as needed). </p><p></p><p>As such, data associated with existing <code>unique keys</code> continues to grow with each data pull.</p></td></tr></tbody></table>

The diagram below illustrates this:

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

{% hint style="info" %}
For information about setting the **append** option, please see our [Appending data to a cache](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/appending-data-to-a-cache.md) page.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/cache/add-to-cache-shape/cache-pagination-options.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
