Whenusing[CacheComponents](/docs/app/getting-started/cache-components),youcanusethe[`use cache`](/docs/app/api-reference/directives/use-cache)directivetocachedatafetchingwithinyourRouteHandlers.RouteHandlersaredynamicbydefault,butcanbepre-renderedatbuildtimeiftheydon't use runtime or dynamic data.
```ts filename="app/api/posts/route.ts" switcher
import { cacheTag } from 'next/cache'
async function getPosts() {
'usecache'
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() {
'usecache'
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.
> **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.