Update directives

parent 42f5931d
...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers' ...@@ -2,7 +2,7 @@ import { cookies } from 'next/headers'
import React from 'react' import React from 'react'
async function getData() { async function getData() {
'use cache' 'use cache: remote'
return fetch('https://next-data-api-endpoint.vercel.app/api/random', { return fetch('https://next-data-api-endpoint.vercel.app/api/random', {
headers: { headers: {
......
async function getCached({ p }) { async function getCached({ p }) {
'use cache' 'use cache: remote'
const array = await p const array = await p
if (array instanceof Uint8Array) { if (array instanceof Uint8Array) {
return array[0].toString(16) + '-' + Math.random() return array[0].toString(16) + '-' + Math.random()
......
import React from 'react' import React from 'react'
async function getData() { async function getData() {
'use cache' 'use cache: remote'
return fetch('https://next-data-api-endpoint.vercel.app/api/random', { return fetch('https://next-data-api-endpoint.vercel.app/api/random', {
next: { revalidate: 0 }, next: { revalidate: 0 },
......
import { setTimeout } from 'timers/promises' import { setTimeout } from 'timers/promises'
export async function getCachedData() { export async function getCachedData() {
'use cache' 'use cache: remote'
await setTimeout(1000) await setTimeout(1000)
return new Date().toISOString() return new Date().toISOString()
} }
...@@ -4,7 +4,7 @@ import { getCachedData } from './cached-data' ...@@ -4,7 +4,7 @@ import { getCachedData } from './cached-data'
export async function generateMetadata(): Promise<Metadata> { export async function generateMetadata(): Promise<Metadata> {
// TODO: Deduping with nested caches requires #78703. // TODO: Deduping with nested caches requires #78703.
// 'use cache' // 'use cache: remote'
await connection() await connection()
......
import { Foo } from '../client' import { Foo } from '../client'
async function getCachedRandom(x: number, children: React.ReactNode) { async function getCachedRandom(x: number, children: React.ReactNode) {
'use cache' 'use cache: remote'
return { return {
x, x,
y: Math.random(), y: Math.random(),
......
...@@ -4,7 +4,7 @@ import Link from 'next/link' ...@@ -4,7 +4,7 @@ import Link from 'next/link'
import { connection } from 'next/server' import { connection } from 'next/server'
async function getCachedValue() { async function getCachedValue() {
'use cache' 'use cache: remote'
cacheTag('revalidate-and-redirect') cacheTag('revalidate-and-redirect')
return Math.random() return Math.random()
......
...@@ -9,7 +9,7 @@ async function fetchCachedValue() { ...@@ -9,7 +9,7 @@ async function fetchCachedValue() {
} }
async function getCachedValue() { async function getCachedValue() {
'use cache' 'use cache: remote'
unstable_cacheTag('revalidate-and-use') unstable_cacheTag('revalidate-and-use')
return Math.random() return Math.random()
} }
......
import { unstable_cacheLife } from 'next/cache' import { unstable_cacheLife } from 'next/cache'
async function getCachedRandom(n: number) { async function getCachedRandom(n: number) {
'use cache' 'use cache: remote'
unstable_cacheLife('weeks') unstable_cacheLife('weeks')
return String(Math.ceil(Math.random() * n)) return String(Math.ceil(Math.random() * n))
} }
......
import { unstable_cacheTag } from 'next/cache' import { unstable_cacheTag } from 'next/cache'
async function getCachedRandom() { async function getCachedRandom() {
'use cache' 'use cache: remote'
unstable_cacheTag('api') unstable_cacheTag('api')
return Math.random() return Math.random()
......
import React from 'react' import React from 'react'
async function getData() { async function getData() {
'use cache' 'use cache: remote'
return fetch( return fetch(
'https://next-data-api-endpoint.vercel.app/api/random?no-store', 'https://next-data-api-endpoint.vercel.app/api/random?no-store',
......
import React from 'react' import React from 'react'
async function getData() { async function getData() {
'use cache' 'use cache: remote'
return fetch('https://next-data-api-endpoint.vercel.app/api/random').then( return fetch('https://next-data-api-endpoint.vercel.app/api/random').then(
(res) => res.text() (res) => res.text()
......
import { unstable_cacheLife as cacheLife } from 'next/cache' import { unstable_cacheLife as cacheLife } from 'next/cache'
async function getCachedRandom() { async function getCachedRandom() {
'use cache' 'use cache: remote'
cacheLife('frequent') cacheLife('frequent')
return Math.random() return Math.random()
} }
......
...@@ -9,7 +9,7 @@ async function getCachedWithTag({ ...@@ -9,7 +9,7 @@ async function getCachedWithTag({
tag: string tag: string
fetchCache?: 'force' | 'revalidate' fetchCache?: 'force' | 'revalidate'
}) { }) {
'use cache' 'use cache: remote'
cacheTag(tag, 'c') cacheTag(tag, 'c')
// If `force-cache` or `revalidate` is used for the fetch call, it creates // If `force-cache` or `revalidate` is used for the fetch call, it creates
......
...@@ -5,7 +5,7 @@ async function getCachedValue( ...@@ -5,7 +5,7 @@ async function getCachedValue(
iterable: Iterable<number>, iterable: Iterable<number>,
fn: () => string fn: () => string
): Promise<[string, () => string]> { ): Promise<[string, () => string]> {
'use cache' 'use cache: remote'
// Make sure we're always receiving the arguments the same way, regardless of // Make sure we're always receiving the arguments the same way, regardless of
// whether draft mode is enabled or not. We're asserting that by checking // whether draft mode is enabled or not. We're asserting that by checking
...@@ -27,13 +27,13 @@ export default async function Page({ ...@@ -27,13 +27,13 @@ export default async function Page({
}: { }: {
params: Promise<{ mode: string }> params: Promise<{ mode: string }>
}) { }) {
'use cache' 'use cache: remote'
const { mode } = await params const { mode } = await params
const offset = 1000 const offset = 1000
const cachedClosure = async () => { const cachedClosure = async () => {
'use cache' 'use cache: remote'
return new Date(Date.now() + offset).toISOString() return new Date(Date.now() + offset).toISOString()
} }
......
...@@ -6,7 +6,7 @@ async function refresh() { ...@@ -6,7 +6,7 @@ async function refresh() {
} }
export default async function Page() { export default async function Page() {
'use cache' 'use cache: remote'
cacheTag('home') cacheTag('home')
return ( return (
......
'use cache' 'use cache: remote'
function getRandomValue() { function getRandomValue() {
const v = Math.random() const v = Math.random()
......
async function Bar() { async function Bar() {
'use cache' 'use cache: remote'
const date = new Date().toLocaleTimeString() const date = new Date().toLocaleTimeString()
console.log('deep inside', date) console.log('deep inside', date)
return <p>{date}</p> return <p>{date}</p>
} }
async function Foo() { async function Foo() {
'use cache' 'use cache: remote'
console.log('inside') console.log('inside')
return <Bar /> return <Bar />
} }
......
export function createCached(n: number) { export function createCached(n: number) {
return { return {
async getRandomValue() { async getRandomValue() {
'use cache' 'use cache: remote'
const v = n + Math.random() const v = n + Math.random()
console.log(v) console.log(v)
return v return v
......
import { revalidatePath, unstable_cache } from 'next/cache' import { revalidatePath, unstable_cache } from 'next/cache'
async function inner() { async function inner() {
'use cache' 'use cache: remote'
return Math.random() return Math.random()
} }
......
'use cache' 'use cache: remote'
import { notFound } from 'next/navigation' import { notFound } from 'next/navigation'
......
...@@ -2,7 +2,7 @@ import { revalidatePath } from 'next/cache' ...@@ -2,7 +2,7 @@ import { revalidatePath } from 'next/cache'
import { RevalidateButtons } from './revalidate-buttons' import { RevalidateButtons } from './revalidate-buttons'
async function cachedValue() { async function cachedValue() {
'use cache' 'use cache: remote'
return Math.random() return Math.random()
} }
......
...@@ -11,15 +11,15 @@ export default function Page() { ...@@ -11,15 +11,15 @@ export default function Page() {
return ( return (
<Form <Form
foo={async function fooNamed() { foo={async function fooNamed() {
'use cache' 'use cache: remote'
return offset + getRandomValue() return offset + getRandomValue()
}} }}
bar={async function () { bar={async function () {
'use cache' 'use cache: remote'
return offset + getRandomValue() return offset + getRandomValue()
}} }}
baz={async () => { baz={async () => {
'use cache' 'use cache: remote'
return offset + getRandomValue() return offset + getRandomValue()
}} }}
/> />
......
...@@ -2,17 +2,17 @@ import { connection } from 'next/server' ...@@ -2,17 +2,17 @@ import { connection } from 'next/server'
import { Suspense } from 'react' import { Suspense } from 'react'
async function outermost(id: string) { async function outermost(id: string) {
'use cache' 'use cache: remote'
return id + middle('middle') return id + middle('middle')
} }
async function middle(id: string) { async function middle(id: string) {
'use cache' 'use cache: remote'
return id + innermost('inner') return id + innermost('inner')
} }
async function innermost(id: string) { async function innermost(id: string) {
'use cache' 'use cache: remote'
return id return id
} }
......
...@@ -10,7 +10,7 @@ function Component() { ...@@ -10,7 +10,7 @@ function Component() {
} }
async function getCachedComponent() { async function getCachedComponent() {
'use cache' 'use cache: remote'
return ( return (
<div> <div>
<p id="a">{number()}</p> <p id="a">{number()}</p>
......
/* eslint-disable no-self-compare */ /* eslint-disable no-self-compare */
async function getObject(arg: unknown) { async function getObject(arg: unknown) {
'use cache' 'use cache: remote'
return { arg } return { arg }
} }
async function getObjectWithBoundArgs(arg: unknown) { async function getObjectWithBoundArgs(arg: unknown) {
async function getCachedObject() { async function getCachedObject() {
'use cache' 'use cache: remote'
return { arg } return { arg }
} }
......
import { ClientComponent } from './client' import { ClientComponent } from './client'
async function getLargeObject() { async function getLargeObject() {
'use cache' 'use cache: remote'
return { hello: 'world' } return { hello: 'world' }
} }
......
export class Cached { export class Cached {
static async getRandomValue() { static async getRandomValue() {
'use cache' 'use cache: remote'
const v = Math.random() const v = Math.random()
console.log(v) console.log(v)
return v return v
......
'use cache' 'use cache: remote'
export async function getRandomValue() { export async function getRandomValue() {
const v = Math.random() const v = Math.random()
......
...@@ -7,7 +7,7 @@ async function action() { ...@@ -7,7 +7,7 @@ async function action() {
} }
export default async function Page() { export default async function Page() {
'use cache' 'use cache: remote'
return ( return (
<Form action={action}> <Form action={action}>
......
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