cloudflare: dont cache no-cache headers (#3849)
The `cache-control` setting was being put into the Cloudflare cache (if Disable Cache was on). We need to not being caching that header. example: <img width="872" alt="Screenshot 2024-05-30 at 13 56 23" src="https://github.com/tldraw/tldraw/assets/469604/12c58ea2-d068-4bc3-b0d5-209274ec3c9c"> ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [ ] `sdk` — Changes the tldraw SDK - [x] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [x] `bugfix` — Bug fix - [ ] `feature` — New feature - [ ] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Release Notes - Cloudflare: don't cache no-cache headers.
This commit is contained in:
parent
c66da1013e
commit
cd96c35f72
1 changed files with 7 additions and 2 deletions
|
@ -39,6 +39,8 @@ function objectNotFound(objectName: string): Response {
|
|||
})
|
||||
}
|
||||
|
||||
const CACHE_CONTROL_SETTING = 's-maxage=604800'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router
|
||||
|
@ -97,7 +99,7 @@ router
|
|||
|
||||
// Cache API respects Cache-Control headers. Setting s-max-age to 7 days
|
||||
// Any changes made to the response here will be reflected in the cached value
|
||||
headers.append('Cache-Control', 's-maxage=604800')
|
||||
headers.append('Cache-Control', CACHE_CONTROL_SETTING)
|
||||
|
||||
const hasBody = 'body' in object && object.body
|
||||
const status = hasBody ? (range ? 206 : 200) : 304
|
||||
|
@ -108,7 +110,10 @@ router
|
|||
|
||||
// Store the response in the cache for future access
|
||||
if (!range) {
|
||||
ctx.waitUntil(cache.put(cacheKey, response.clone()))
|
||||
const clonedResponse = response.clone()
|
||||
// If the request was made with no-cache, we should not cache that in the headers.
|
||||
clonedResponse?.headers.set('Cache-Control', CACHE_CONTROL_SETTING)
|
||||
ctx.waitUntil(cache.put(cacheKey, clonedResponse))
|
||||
}
|
||||
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue