> For the complete documentation index, see [llms.txt](https://developer.esw.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.esw.com/adobe-commerce-magento/integration/calculated-pricing-cache-setup.md).

# Calculated Pricing Cache Setup

If your store uses the [Calculated Pricing Model](/adobe-commerce-magento/adobe-commerce-extension-integration/getting-started/pricing-model.md) for multiple countries on the same storefront URL, cache variation must include the ESW shopper location.

Without this setup, cached pages can return pricing for the wrong market.

### When this setup is required

Apply this configuration when all of these are true:

* multiple countries share the same store URL
* country selection is driven by the ESW `esw-location` cookie
* Fastly CDN or Varnish caches HTML responses
* localized prices depend on the shopper country

### How the cache variation works

The cache key must vary by the `esw-location` cookie value.

This ensures that each market gets its own cached page version.

In practice:

* the request phase reads the `esw-location` cookie
* the value is copied into a request header
* the response phase adds that header to `Vary` for HTML and XML content

### Fastly or Varnish configuration

Add these example snippets to your Fastly custom VCL or Varnish configuration.

#### Request snippet

Use this logic in `vcl_recv`:

```sql
if (req.http.Cookie ~ "esw-location=") {
  set req.http.Esw-location = regsub(req.http.cookie, "^.*?esw-location=([^;]+);*.*$", "\1");
} else {
  set req.http.Esw-location = "";
}
```

#### Response snippet

Use this logic in `vcl_fetch`:

```sql
if (beresp.http.Content-Type ~ "text/(html|xml)") {
  if (beresp.http.Vary) {
    set beresp.http.Vary = beresp.http.Vary ",Esw-location";
  }
}
```

{% hint style="warning" %}
These are example snippets. Validate them against your Fastly module version, Varnish version, and existing custom VCL before deploying to production.
{% endhint %}

### Verify the setup

After the cache rule is deployed:

1. Open the same product or category page for two different ESW markets.
2. Confirm that each market shows the correct localized price.
3. Repeat the test after the page is served from cache.
4. Confirm that cached HTML varies by the `Esw-location` header or the derived cache key.

### Expected result

After setup is complete:

* cached storefront pages vary by shopper country
* calculated pricing stays aligned with the selected market
* shoppers do not see cached prices from another country


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developer.esw.com/adobe-commerce-magento/integration/calculated-pricing-cache-setup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
