purge cache with DELETE method

This commit is contained in:
m5r
2025-09-20 14:35:51 +02:00
parent 2acd6e0bc4
commit a3d639df6c
4 changed files with 57 additions and 2 deletions

View File

@@ -19,6 +19,17 @@ export default {
const cache = caches.default;
const cacheKey = new Request(`${url.origin}/cache/${encodeURIComponent(targetUrl)}`);
if (request.method === "DELETE") {
const deleted = await cache.delete(cacheKey);
return new Response(deleted ? "Cache entry deleted" : "Cache entry not found", {
status: deleted ? 200 : 404,
headers: {
"Content-Type": "text/plain",
"Access-Control-Allow-Origin": "*",
},
});
}
let response = await cache.match(cacheKey);
if (response) {
return response;