Edit in GitHubLog an issue

Edge caching

API Mesh for Adobe Developer App Builder supports edge caching if you provide your own content delivery network (CDN), such as Fastly. Edge caching helps improve website load times and reduces consumption costs associated with bandwidth.

Cache-control headers

A CDN's cache-control headers determine how queried information is cached.

When a browser or a GET request accesses a URL, the site's response headers typically include a cache-control header, which determines how long the site will allow its data to be cached. For example, a website could have the following response header:

Copied to your clipboard
cache-control: max-age=0

The max-age=0 cache-control directive means that this site wants to serve fresh data until 0 seconds after the response is generated, which basically means it never wants to cache data. This could also be achieved with a no-store directive.

For more information on specific cache-control directives and how they can be used, see the Mozilla Developer Network's cache control guide.

Using cache-control headers with API Mesh

API mesh users can add cache-control headers to request headers or to a mesh configuration file.

As request headers

Use a mesh configuration similar to the example below to return forwarded headers.

When the response includes cache-control values, only the most restrictive values are returned.

Copied to your clipboard
{
"meshConfig": {
"responseConfig": {
"headers": {
"Cache-Control": "max-age=50,min-fresh=6,stale-if-error=20,public,must-revalidate"
}
},
"sources": [
{
"name": "venia",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql"
}
}
}
]
}
}

How conflicting header values are resolved

When cache-control header values from multiple sources conflict, API Mesh selects the lowest or most restrictive value. The following section explains which values are returned when cache-control directives conflict.

The no-store directive supersedes all other directives. If your source's cache-control headers contain this directive, then the mesh does not return other headers.

If your source's cache-control headers contain conflicting values for the following directives, the mesh selects the lowest value:

  • min-fresh

  • max-age

  • max-stale

  • s-maxage

  • stale-if-error

  • stale-while-revalidate

If your source's cache-control headers contain any of the following directives, the mesh adds the directive to the cache-control response.

  • public

  • private

  • immutable

  • no-cache

  • no-transform

  • must-revalidate

  • proxy-revalidate

  • must-understand

Examples

The following example scenarios indicate the resulting Response header from two conflicting sources:

Example 1

  • Source 1 response headers

    • max-age=3600, stale-while-revalidate=60, stale-if-error=3600
  • Source 2 response headers

    • max-age:600, stale-if-error=60
  • Combined HTTP response headers

    • max-age=600, stale-while-revalidate=60, stale-if-error=60

Example 2

  • Source 1 response headers

    • max-age=3600, stale-while-revalidate=60, stale-if-error=3600
  • Source 2 response headers

    • no-store
  • Combined HTTP response headers

    • no-store

In the mesh configuration file

To set your own values for cache-control headers, add a Cache-Control key-value pair to the responseConfig object in your mesh configuration file.

Mesh Example

Copied to your clipboard
{
"meshConfig": {
"responseConfig": {
"headers": {
"Cache-Control": "max-age=50,min-fresh=6,stale-if-error=20,public,must-revalidate"
}
},
"sources": [
{
"name": "venia",
"handler": {
"graphql": {
"endpoint": "https://venia.magento.com/graphql"
}
}
}
]
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2023 Adobe. All rights reserved.