Commit 2069391
authored
Cache fixing by unit path invalidation instead of individual file listing (#1464)
Closes
RaspberryPiFoundation/digital-editor-issues#1371
#### What changed
This PR changes the deploy workflow to purge Cloudflare by deployed path
prefix instead of by a hard-coded list of individual files.
A staging deploy now purges:
```bash
{
"prefixes": [
"staging-editor-static.raspberrypi.org/branches/main/"
]
}
```
while before:
```bash
{
"files": [
"https://staging-editor-static.raspberrypi.org/branches/main/web-component.html",
"https://staging-editor-static.raspberrypi.org/branches/main/web-component.js",
"https://staging-editor-static.raspberrypi.org/branches/main/scratch.html",
"https://staging-editor-static.raspberrypi.org/branches/main/scratch.js",
"https://staging-editor-static.raspberrypi.org/latest_version",
"https://staging-editor-static.raspberrypi.org/branches/main/html-renderer.html",
"https://staging-editor-static.raspberrypi.org/branches/main/html-renderer.js"
]
}
```
The PR also uploads latest_version with Cache-Control: no-cache, because
that file is intentionally updated in place.
For production tags, before it purged individual files inside one
release plus latest_version. Now it purges:
```bash
{
"prefixes": [
"editor-static.raspberrypi.org/releases/<tag>/",
"editor-static.raspberrypi.org/latest_version"
]
}
```
## Why
Staging should serve the latest deployed version of editor-ui after each
deploy.
The previous single-file purge targeted paths such as
`web-component.js`, `scratch.js`, and `html-renderer.js`. That can be
unreliable because Cloudflare may cache separate variants of the same
URL when request headers differ, for example with different Origin
headers. If the purge request does not match the cached variant,
Cloudflare can continue serving an older file. Prefix purging clears the
deployed build path as a unit. The next request after deploy fetches the
updated files from the bucket, and Cloudflare then caches those files
again as normal.
This is a targeted deploy/cache invalidation fix.
References:
- Purge cache by prefix
(https://developers.cloudflare.com/cache/how-to/purge-cache/purge_by_prefix/)
- Cloudflare documents prefix purge for clearing a directory/path,
reducing purge calls, and causing the next request to refetch from
origin.
- Purge Cached Content API
(https://developers.cloudflare.com/api/resources/cache/methods/purge/)
- Cache Keys
(https://developers.cloudflare.com/cache/how-to/cache-keys/)
- Purge by single-file
(https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/)
- Origin Cache Control
(https://developers.cloudflare.com/cache/concepts/cache-control/)
- Browser Cache TTL
(https://developers.cloudflare.com/cache/how-to/edge-browser-cache-ttl/set-browser-ttl/)
Idea:
Longer term, we should move to content-hashed asset filenames with
immutable caching, leaving only small stable entrypoints or manifests as
revalidated files.1 parent cc794bd commit 2069391
1 file changed
Lines changed: 49 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
| 176 | + | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| |||
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
184 | 226 | | |
185 | 227 | | |
186 | 228 | | |
187 | 229 | | |
188 | | - | |
| 230 | + | |
189 | 231 | | |
190 | 232 | | |
191 | 233 | | |
| |||
198 | 240 | | |
199 | 241 | | |
200 | 242 | | |
201 | | - | |
| 243 | + | |
202 | 244 | | |
203 | 245 | | |
204 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
0 commit comments