-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shim): add nginx cache purger on pre-registration (#469)
* feat(shim): add nginx cache purger on pre-registration * Don't fail on unlink failures * Update deps
- Loading branch information
Diego Rodríguez Baquero
authored
Aug 14, 2023
1 parent
d121b8e
commit de1e497
Showing
4 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import fs from "node:fs/promises"; | ||
import { createHash } from "node:crypto"; | ||
import path from "node:path"; | ||
import { debug } from "./logging.js"; | ||
|
||
const CACHE_DIR = "/usr/src/app/shared/nginx_cache"; | ||
|
||
export async function purgeCacheFile(key) { | ||
debug("Purging cache file for key %s", key); | ||
const cacheFilePath = keyToCacheFilePath(key); | ||
await fs | ||
.unlink(path.join(CACHE_DIR, cacheFilePath)) | ||
.catch((err) => debug("Failed to purge cache file: %s", err.message)); | ||
} | ||
|
||
function keyToCacheFilePath(path) { | ||
const hash = createHash("md5").update(path).digest("hex"); | ||
|
||
return `${hash.slice(-2)}/${hash.slice(-4, -2)}/${hash.slice(-6, -4)}/${hash}`; | ||
} |