-
Notifications
You must be signed in to change notification settings - Fork 29.7k
docs: added use cache: remote
docs
#85145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
All broken links are now fixed, thank you! |
async function getProductPrice(productId: string) { | ||
'use cache: remote' | ||
cacheTag(`product-price-${productId}`) | ||
cacheLife({ stale: 3600 }) // 1 hour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean revalidate
? I thought stale
was the client-side cache.
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
|
||
When Next.js encounters certain APIs like [`connection()`](/docs/app/api-reference/functions/connection), [`cookies()`](/docs/app/api-reference/functions/cookies), or [`headers()`](/docs/app/api-reference/functions/headers), the context becomes "dynamic". In a dynamic context: | ||
|
||
1. **Regular `use cache` stops working** - it won't cache anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that it'll error in development? Because the fear is that this will happen silently.
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
|
||
> **Good to know:** Without `'use cache: remote'`, functions in dynamic contexts would execute on every request, potentially creating performance bottlenecks. Remote caching eliminates this issue by storing results in server-side cache handlers. | ||
|
||
### Storage behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere in this section, you may want to link to how to configure cache handlers. Otherwise, it's not actionable.
docs/01-app/03-api-reference/01-directives/use-cache-remote.mdx
Outdated
Show resolved
Hide resolved
} | ||
``` | ||
|
||
> **Good to know**: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this section is repetitive, since we already mentioned when to use each.
I do like the distinction between using cacheTag
to revalidate, and cacheLife
to expire, good wording.
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Added documentation for
use cache: remote
.