feat(api): POST /api/cache/clear + flush images on asset webhooks
Deploy / verify (push) Failing after 38s
Deploy / deploy (push) Has been skipped

Two changes:
- New POST /api/cache/clear (auth: REVALIDATE_TOKEN). Wipes the
  TTL content cache, the image disk + memory cache, and forwards to
  the RustyCMS /api/transform/cache/invalidate endpoint when an
  API key is configured. Single trigger to flush everything.
- /api/revalidate now also calls clearImageCache() on asset.* events
  so a re-upload (focal change, alt edit, replacement) doesn't keep
  serving the previous transformed image from disk.

clearImageCache() in image-cache.server.ts wipes the in-memory map
and removes every file under IMAGE_CACHE_DIR.
This commit is contained in:
Peter Meier
2026-04-25 09:20:48 +02:00
parent 7264ad6707
commit 1ff4dc7a9a
3 changed files with 74 additions and 1 deletions
+24
View File
@@ -218,3 +218,27 @@ export function resolveExtension(params: ImageTransformParams, contentType?: str
if (contentType) return extForContentType(contentType);
return 'jpg';
}
/**
* Wipe in-memory + on-disk image cache. Returns counts cleared.
*/
export async function clearImageCache(): Promise<{ memory: number; disk: number }> {
const memory = memoryCache.size;
memoryCache.clear();
let disk = 0;
try {
const dir = ensureCacheDir();
const files = await readdir(dir);
for (const f of files) {
try {
await unlink(join(dir, f));
disk++;
} catch {
/* ignore */
}
}
} catch {
/* ignore */
}
return { memory, disk };
}