File tree Expand file tree Collapse file tree 4 files changed +41
-30
lines changed
packages/nextjs-cache-handler Expand file tree Collapse file tree 4 files changed +41
-30
lines changed Original file line number Diff line number Diff line change 1010 "type" : " git" ,
1111 "url" : " git+https://github.com/fortedigital/nextjs-cache-handler.git"
1212 },
13- "version" : " 1.3.0-canary4 " ,
13+ "version" : " 1.3.0-canary5 " ,
1414 "type" : " module" ,
1515 "license" : " MIT" ,
1616 "description" : " Next.js cache handlers" ,
Original file line number Diff line number Diff line change 1- import { Handler } from "@neshca/cache-handler" ;
1+ import { CacheHandlerValue , Handler } from "@neshca/cache-handler" ;
22import {
33 CachedAppPageValue ,
44 CachedRouteValue ,
55 ConvertedCachedAppPageValue ,
66 ConvertedCachedRouteValue ,
77} from "./buffer-string-decorator.types" ;
8+ import { IncrementalCacheValue } from "next/dist/server/response-cache" ;
9+ import { Next15IncrementalCacheValue } from "./next15.types" ;
810
911/*
1012 * This cache handler converts buffers from cached route values to strings on save and back to buffers on read.
@@ -64,7 +66,12 @@ export default function bufferStringDecorator(handler: Handler): Handler {
6466 } ,
6567
6668 async set ( key , data ) {
67- const value = data . value ;
69+ if ( ! data ?. value ) {
70+ await handler . set ( key , data ) ;
71+ return ;
72+ }
73+
74+ const value = { ...data . value } ;
6875 const kind = value ?. kind as string ;
6976
7077 if ( kind === "APP_ROUTE" ) {
@@ -100,7 +107,7 @@ export default function bufferStringDecorator(handler: Handler): Handler {
100107 }
101108 }
102109
103- await handler . set ( key , data ) ;
110+ await handler . set ( key , { ... data , value } ) ;
104111 } ,
105112
106113 async revalidateTag ( tag ) {
Original file line number Diff line number Diff line change 11import { CacheHandler } from "@neshca/cache-handler" ;
2- import { OutgoingHttpHeaders } from "http" ;
32import {
4- CachedRedirectValue ,
5- CachedImageValue ,
63 CachedFetchValue ,
74 IncrementalCacheValue ,
85} from "next/dist/server/response-cache" ;
9-
10- export interface CachedRouteValue {
11- kind : "APP_ROUTE" ;
12- body : Buffer ;
13- status : number ;
14- headers : OutgoingHttpHeaders ;
15- }
16-
17- interface IncrementalCachedPageValue {
18- kind : "APP_PAGE" ;
19- html : string ;
20- pageData : Object ;
21- postponed : string | undefined ;
22- headers : OutgoingHttpHeaders | undefined ;
23- status : number | undefined ;
24- }
25-
26- export type Next15IncrementalCacheValue =
27- | CachedRedirectValue
28- | IncrementalCachedPageValue
29- | CachedImageValue
30- | CachedFetchValue
31- | CachedRouteValue ;
6+ import { Next15IncrementalCacheValue } from "./next15.types" ;
327
338/*
349 * Use this handler in Next 15.2.1 and higher after `revalidate` property had been removed from context object.
Original file line number Diff line number Diff line change 1+ import {
2+ CachedRedirectValue ,
3+ CachedImageValue ,
4+ CachedFetchValue ,
5+ } from "next/dist/server/response-cache" ;
6+ import { OutgoingHttpHeaders } from "http" ;
7+
8+ export interface CachedRouteValue {
9+ kind : "APP_ROUTE" ;
10+ body : Buffer ;
11+ status : number ;
12+ headers : OutgoingHttpHeaders ;
13+ }
14+
15+ export interface IncrementalCachedPageValue {
16+ kind : "APP_PAGE" ;
17+ html : string ;
18+ pageData : Object ;
19+ postponed : string | undefined ;
20+ headers : OutgoingHttpHeaders | undefined ;
21+ status : number | undefined ;
22+ }
23+
24+ export type Next15IncrementalCacheValue =
25+ | CachedRedirectValue
26+ | IncrementalCachedPageValue
27+ | CachedImageValue
28+ | CachedFetchValue
29+ | CachedRouteValue ;
You can’t perform that action at this time.
0 commit comments