Skip to content

Commit

Permalink
Add special path to clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed Jun 27, 2024
1 parent de2ade5 commit c395600
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions client_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,19 @@ export class ClientManager {
}
this.#updates.set(client, []);
}

async clearCache() {
for (const client of this.#clients.values()) {
try {
await client.storage.clear();
} catch (_err) {
await client.storage.initialize();
try {
await client.storage.clear();
} catch (_err) {
//
}
}
}
}
}
5 changes: 5 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ Deno.serve({
case "/write-logs":
await workers.unload();
return Response.json("Logs were written.");
case "/clear-cache":
for (let i = 0; i < workers.count(); ++i) {
await workers.call(i, "clearCache");
}
return Response.json("Caches were cleared.");
default:
return notFound();
}
Expand Down
3 changes: 2 additions & 1 deletion stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ function Stats({ children: workers }: { children: WorkerStats[] }) {
SPECIAL PATHS
<NewLine />
<Indent>
/write-logs
/write-logs{"\n"}
/clear-cache
</Indent>
<BlankLine />
<BlankLine />
Expand Down
6 changes: 6 additions & 0 deletions worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const handlers = {
startWebhookLoop,
unload,
dropPendingUpdates,
clearCache,
};
export type Handler = typeof handlers;

Expand Down Expand Up @@ -272,3 +273,8 @@ async function dropPendingUpdates(
await clientManager.dropPendingUpdates(id);
return [null];
}

async function clearCache(): Promise<Parameters<typeof Response["json"]>> {
await clientManager.clearCache();
return [null];
}

0 comments on commit c395600

Please sign in to comment.