Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #314

Merged
merged 3 commits into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions cms-cache-purger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ export default {
async function deleteContentsCache(env: Env) {
const list = await env.CMS_CACHE.list({ prefix: 'contents_' })
// すべての contents_ から始まるキーを削除する
list.keys.forEach(async (key) => {
await env.CMS_CACHE.delete(key.name)
console.log(`delete cache: ${key.name}`)
const deleteKeys = await Promise.all(
list.keys.map(async (key) => {
await env.CMS_CACHE.delete(key.name)
return key.name
})
)
deleteKeys.forEach((key) => {
console.log(`Deleted: ${key}`)
})

if (list.list_complete === false) {
// キャッシュがまだある場合は再帰的に削除する
await deleteContentsCache(env)
Expand All @@ -80,12 +86,7 @@ async function deleteContentsCache(env: Env) {

async function deleteContentCache(env: Env, contentID: string) {
const cacheKey = generateContentKey(contentID)
const cache = await env.CMS_CACHE.get(cacheKey)
if (!cache) {
// キャッシュがなかったのでパス
return
}
await env.CMS_CACHE.delete(cacheKey)
await deleteCache(env, cacheKey)
}

async function deleteCache(env: Env, cacheKey: string) {
Expand Down