-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed26ce2
commit b893379
Showing
3 changed files
with
10 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// For scheduled R2 cache busting, the R2 lifecycle rules can be used to delete an object after a certain amount of time. | ||
|
||
async function bustEntireCache(list: R2Objects, env: Env) { | ||
for (const object of list.objects) { | ||
await env.R2_ARTIFACT_ARCHIVE.delete(object.key); | ||
} | ||
async function bustEntireCache(list: R2Objects, R2_ARTIFACT_ARCHIVE: Env['R2_ARTIFACT_ARCHIVE']) { | ||
const allObjectKeys = list.objects.map((o) => o.key); | ||
|
||
await R2_ARTIFACT_ARCHIVE.delete(allObjectKeys); | ||
} | ||
|
||
export async function bustOldCache(env: Env, cursor?: string) { | ||
const list = await env.R2_ARTIFACT_ARCHIVE.list({ | ||
export async function bustOldCache(R2_ARTIFACT_ARCHIVE: Env['R2_ARTIFACT_ARCHIVE'], cursor?: string) { | ||
const list = await R2_ARTIFACT_ARCHIVE.list({ | ||
limit: 500, | ||
cursor, | ||
}); | ||
await bustEntireCache(list, env); | ||
await bustEntireCache(list, R2_ARTIFACT_ARCHIVE); | ||
|
||
if (list.truncated) { | ||
await bustOldCache(env, list.cursor); | ||
await bustOldCache(R2_ARTIFACT_ARCHIVE, list.cursor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters