---
title: generateCacheControlHeader
description: This utility function accepts a CachingStrategy object and returns a string with the corresponding cache-control header.
api_version: 2026-04
api_name: hydrogen
source_url:
  html: https://shopify.dev/docs/api/hydrogen/2025-01/utilities/caching/generatecachecontrolheader
  md: https://shopify.dev/docs/api/hydrogen/2025-01/utilities/caching/generatecachecontrolheader.md
---

# generateCacheControlHeader

This utility function accepts a `CachingStrategy` object and returns a string with the corresponding `cache-control` header.

Learn more about [data fetching in Hydrogen](https://shopify.dev/docs/custom-storefronts/hydrogen/data-fetching/fetch-data).

## generate​Cache​Control​Header(**[cacheOptions](#arguments-propertydetail-cacheoptions)**​)

### Parameters

* **cacheOptions**

  **AllCacheOptions**

  **required**

### Returns**string**

### AllCacheOptions

Override options for a cache strategy.

* maxAge

  The maximum amount of time in seconds that a resource will be considered fresh. See \`max-age\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#:\~:text=Response%20Directives-,max%2Dage,-The%20max%2Dage).

  ```ts
  number
  ```

* mode

  The caching mode, generally \`public\`, \`private\`, or \`no-store\`.

  ```ts
  string
  ```

* sMaxAge

  Similar to \`maxAge\` but specific to shared caches. See \`s-maxage\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-maxage).

  ```ts
  number
  ```

* staleIfError

  Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See \`stale-if-error\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error).

  ```ts
  number
  ```

* staleWhileRevalidate

  Indicate that the cache should serve the stale response in the background while revalidating the cache. See \`stale-while-revalidate\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate).

  ```ts
  number
  ```

Examples

### Examples

* #### Example code

  ##### JavaScript

  ```js
  import {data} from 'react-router';
  import {generateCacheControlHeader, CacheShort} from '@shopify/hydrogen';

  export async function loader() {
    return data(
      {some: 'data'},
      {
        headers: {
          'cache-control': generateCacheControlHeader(CacheShort()),
        },
      },
    );
  }
  ```

  ##### TypeScript

  ```ts
  import {data} from 'react-router';
  import {generateCacheControlHeader, CacheShort} from '@shopify/hydrogen';

  export async function loader() {
    return data(
      {some: 'data'},
      {
        headers: {
          'cache-control': generateCacheControlHeader(CacheShort()),
        },
      },
    );
  }
  ```

***