Unverified Commit b57e8147 authored by Sam Ko's avatar Sam Ko Committed by GitHub

docs(route-handlers): add note about caching with other support HTTP methods in…

docs(route-handlers): add note about caching with other support HTTP methods in Route Handlers (#70049)

## Why?

We currently do not clarify that other supported HTTP Methods (all other
besides `GET`) in Route Handlers are not cached. This remains true even
if they are placed alongside a `GET` that is cached.

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent ed242dc7
...@@ -46,7 +46,7 @@ In addition to supporting the native [Request](https://developer.mozilla.org/doc ...@@ -46,7 +46,7 @@ In addition to supporting the native [Request](https://developer.mozilla.org/doc
### Caching ### Caching
Route Handlers are not cached by default. You can, however, opt into caching for `GET` methods. To do so, use a [route config option](/docs/app/api-reference/file-conventions/route-segment-config#dynamic) such as `export const dynamic = 'force-static'` in your Route Handler file. Route Handlers are not cached by default. You can, however, opt into caching for `GET` methods. Other supported HTTP methods are **not** cached. To cache a `GET` method, use a [route config option](/docs/app/api-reference/file-conventions/route-segment-config#dynamic) such as `export const dynamic = 'force-static'` in your Route Handler file.
```ts filename="app/items/route.ts" switcher ```ts filename="app/items/route.ts" switcher
export const dynamic = 'force-static' export const dynamic = 'force-static'
...@@ -80,6 +80,8 @@ export async function GET() { ...@@ -80,6 +80,8 @@ export async function GET() {
} }
``` ```
> **Good to know**: Other supported HTTP methods are **not** cached, even if they are placed alongside a `GET` method that is cached, in the same file.
### Special Route Handlers ### Special Route Handlers
Special Route Handlers like [`sitemap.ts`](/docs/app/api-reference/file-conventions/metadata/sitemap), [`opengraph-image.tsx`](/docs/app/api-reference/file-conventions/metadata/opengraph-image), and [`icon.tsx`](/docs/app/api-reference/file-conventions/metadata/app-icons), and other [metadata files](/docs/app/api-reference/file-conventions/metadata) remain static by default unless they use dynamic functions or dynamic config options. Special Route Handlers like [`sitemap.ts`](/docs/app/api-reference/file-conventions/metadata/sitemap), [`opengraph-image.tsx`](/docs/app/api-reference/file-conventions/metadata/opengraph-image), and [`icon.tsx`](/docs/app/api-reference/file-conventions/metadata/app-icons), and other [metadata files](/docs/app/api-reference/file-conventions/metadata) remain static by default unless they use dynamic functions or dynamic config options.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment