File tree 2 files changed +11
-3
lines changed
packages/adapter-cloudflare/src
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @sveltejs/adapter-cloudflare " : patch
3
+ ---
4
+
5
+ chore(cloudflare): more restrictive cache lookup & save conditions
Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ const prefix = `/${manifest.appDir}/`;
10
10
const worker = {
11
11
async fetch ( req , env , context ) {
12
12
try {
13
- let res = await Cache . lookup ( req ) ;
13
+ // skip cache if "cache-control: no-cache" in request
14
+ let pragma = req . headers . get ( 'cache-control' ) || '' ;
15
+ let res = ! pragma . includes ( 'no-cache' ) && ( await Cache . lookup ( req ) ) ;
14
16
if ( res ) return res ;
15
17
16
18
let { pathname } = new URL ( req . url ) ;
@@ -57,8 +59,9 @@ const worker = {
57
59
}
58
60
}
59
61
60
- // Writes to Cache only if allowed
61
- return Cache . save ( req , res , context ) ;
62
+ // Writes to Cache only if allowed & specified
63
+ pragma = res . headers . get ( 'cache-control' ) ;
64
+ return pragma ? Cache . save ( req , res , context ) : res ;
62
65
} catch ( e ) {
63
66
return new Response ( 'Error rendering route: ' + ( e . message || e . toString ( ) ) , { status : 500 } ) ;
64
67
}
You can’t perform that action at this time.
0 commit comments