File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
packages/next/src/server/web/spec-extension
test/e2e/app-dir/app-static
app/variable-revalidate/revalidate-360 Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,9 @@ export function unstable_cache<T extends Callback>(
8282 const cacheKey = await incrementalCache ?. fetchCacheKey ( joinedKey )
8383 const cacheEntry =
8484 cacheKey &&
85+ // when we are nested inside of other unstable_cache's
86+ // we should bypass cache similar to fetches
87+ store ?. fetchCache !== 'force-no-store' &&
8588 ! (
8689 store ?. isOnDemandRevalidate || incrementalCache . isOnDemandRevalidate
8790 ) &&
Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ createNextDescribe(
222222 const $ = cheerio . load ( html )
223223 const initLayoutData = $ ( '#layout-data' ) . text ( )
224224 const initPageData = $ ( '#page-data' ) . text ( )
225+ const initNestedCacheData = $ ( '#nested-cache' ) . text ( )
225226
226227 const routeHandlerRes = await next . fetch (
227228 '/route-handler/revalidate-360'
@@ -254,6 +255,7 @@ createNextDescribe(
254255 const new$ = cheerio . load ( newHtml )
255256 const newLayoutData = new$ ( '#layout-data' ) . text ( )
256257 const newPageData = new$ ( '#page-data' ) . text ( )
258+ const newNestedCacheData = new$ ( '#nested-cache' ) . text ( )
257259
258260 const newRouteHandlerRes = await next . fetch (
259261 '/route-handler/revalidate-360'
@@ -271,6 +273,7 @@ createNextDescribe(
271273 expect ( newEdgeRouteHandlerData ) . toBeTruthy ( )
272274 expect ( newLayoutData ) . not . toBe ( initLayoutData )
273275 expect ( newPageData ) . not . toBe ( initPageData )
276+ expect ( newNestedCacheData ) . not . toBe ( initNestedCacheData )
274277 expect ( newRouteHandlerData ) . not . toEqual ( initRouteHandlerData )
275278 expect ( newEdgeRouteHandlerData ) . not . toEqual ( initEdgeRouteHandlerRes )
276279 return 'success'
Original file line number Diff line number Diff line change @@ -54,6 +54,33 @@ export default async function Page() {
5454 }
5555 ) ( )
5656
57+ const cacheInner = unstable_cache (
58+ async ( ) => {
59+ console . log ( 'calling cacheInner' )
60+ const data = await fetch (
61+ 'https://next-data-api-endpoint.vercel.app/api/random?something' ,
62+ {
63+ next : { revalidate : 15 , tags : [ 'thankyounext' ] } ,
64+ }
65+ ) . then ( ( res ) => res . text ( ) )
66+ return data
67+ } ,
68+ [ ] ,
69+ { revalidate : 360 }
70+ )
71+
72+ const cacheOuter = unstable_cache (
73+ ( ) => {
74+ console . log ( 'cacheOuter' )
75+ return cacheInner ( )
76+ } ,
77+ [ ] ,
78+ {
79+ revalidate : 1000 ,
80+ tags : [ 'thankyounext' ] ,
81+ }
82+ ) ( )
83+
5784 return (
5885 < >
5986 < p id = "page" > /variable-revalidate/revalidate-360</ p >
@@ -65,6 +92,7 @@ export default async function Page() {
6592 revalidate 10 (tags: thankyounext): { JSON . stringify ( cachedData ) }
6693 </ p >
6794 < p id = "now" > { Date . now ( ) } </ p >
95+ < p id = "nested-cache" > nested cache: { cacheOuter } </ p >
6896 </ >
6997 )
7098}
You can’t perform that action at this time.
0 commit comments