Unverified Commit 7fef3a0c authored by Joseph's avatar Joseph Committed by GitHub

docs: fresh up getting started 00 (#85736)

parent 2f86fbab
......@@ -84,6 +84,46 @@ 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.
#### With Cache Components
When using [Cache Components](/docs/app/getting-started/cache-components), you can use the [`use cache`](/docs/app/api-reference/directives/use-cache) directive to cache data fetching within your Route Handlers. Route Handlers are dynamic by default, but can be pre-rendered at build time if they don't use runtime or dynamic data.
```ts filename="app/api/posts/route.ts" switcher
import { cacheTag } from 'next/cache'
async function getPosts() {
'use cache'
cacheTag('posts')
const posts = await fetchPosts()
return posts
}
export async function GET() {
const posts = await getPosts()
return Response.json(posts)
}
```
```js filename="app/api/posts/route.js" switcher
import { cacheTag } from 'next/cache'
async function getPosts() {
'use cache'
cacheTag('posts')
const posts = await fetchPosts()
return posts
}
export async function GET() {
const posts = await getPosts()
return Response.json(posts)
}
```
See the [Cache Components documentation](/docs/app/getting-started/cache-components#route-handlers-with-cache-components) for more details on caching strategies and revalidation.
### 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 APIs or dynamic config options.
......
......@@ -12,15 +12,19 @@ related:
## Proxy
> **Good to know**: Starting with Next.js 16, Middleware is now called Proxy to better reflect its purpose. The functionality remains the same.
Proxy allows you to run code before a request is completed. Then, based on the incoming request, you can modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.
### Use cases
Some common scenarios where Proxy is effective include:
- Quick redirects after reading parts of the incoming request
- Rewriting to different pages based on A/B tests or experiments
- Modifying headers for all pages or a subset of pages
- Rewriting to different pages based on A/B tests or experiments
- Programmatic redirects based on incoming request properties
For simple redirects, consider using the [`redirects`](/docs/app/api-reference/config/next-config-js/redirects) configuration in `next.config.ts` first. Proxy should be used when you need access to request data or more complex logic.
Proxy is _not_ intended for slow data fetching. While Proxy can be helpful for [optimistic checks](/docs/app/guides/authentication#optimistic-checks-with-proxy-optional) such as permission-based redirects, it should not be used as a full session management or authorization solution.
......
......@@ -48,13 +48,6 @@ npm i next@canary
The following features are currently available in canary:
**Caching**:
- [`"use cache"`](/docs/app/api-reference/directives/use-cache)
- [`cacheLife`](/docs/app/api-reference/functions/cacheLife)
- [`cacheTag`](/docs/app/api-reference/functions/cacheTag)
- [`cacheComponents`](/docs/app/api-reference/config/next-config-js/cacheComponents)
**Authentication**:
- [`forbidden`](/docs/app/api-reference/functions/forbidden)
......
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