You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify remote-cache snippet and add await to db.product.find
Based on Sam's feedback: the readme code snippet only needs to show
getProductPrice, not the ProductPrice component. Also adds the missing
await in front of db.product.find.
Made-with: Cursor
- Use `use cache: remote` to store cache entries in a remote handler (e.g. Redis or KV), providing **durable, shared caching** across all server instances.
13
13
- Regular `use cache` stores entries in-memory, which works for static shell content but may have low hit rates at runtime in serverless environments.
14
-
- Most useful for data accessed at runtime in dynamic components (e.g. those reading `cookies()`, `headers()`, or `connection()`), where remote caching reduces load on rate-limited APIs, slow backends, or expensive operations.
14
+
- Most useful for data that would otherwise be re-fetched on every request, where remote caching reduces load on rate-limited APIs, slow backends, or expensive operations.
15
15
16
16
# !!col
17
17
@@ -20,25 +20,17 @@ async function getProductPrice(productId: string) {
-**Product data** is fetched with `use cache` in `getData()` - cached in the static shell.
41
-
-**Price data** is fetched with `use cache: remote` in `getProductPrice()` - the component reads `cookies()` making it dynamic, so the price is cached in a remote cache at runtime.
33
+
-**Price data** is fetched with `use cache: remote` in `getProductPrice()` - stored durably in a remote cache, shared across all server instances.
42
34
- The price data function uses `cacheTag()` for targeted cache invalidation.
43
35
- Artificial delays (1s for products, 1s for prices) make caching behavior visible.
44
36
- Notice how product data loads once, while price data streams in per product, but is cached for subsequent requests.
0 commit comments