-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
.script/cache.json |
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,40 @@ | ||
import { readFile, writeFile } from "fs/promises"; | ||
|
||
const cache: Record<string, string> = {} | ||
|
||
export function getCache(key: string): string | undefined { | ||
return cache[key]; | ||
} | ||
|
||
export function setCache(key: string, value: string): void { | ||
cache[key] = value; | ||
} | ||
|
||
export function clearCache(): void { | ||
for (const key in cache) { | ||
delete cache[key]; | ||
} | ||
} | ||
|
||
export function deleteCache(key: string): void { | ||
delete cache[key]; | ||
} | ||
|
||
export async function loadCache() { | ||
try { | ||
const data = await readFile(".script/cache.json", "utf-8"); | ||
const parsed = JSON.parse(data); | ||
for (const key in parsed) { | ||
cache[key] = parsed[key]; | ||
} | ||
} catch (e) { | ||
} | ||
} | ||
|
||
export async function saveCache() { | ||
try { | ||
await writeFile(".script/cache.json", JSON.stringify(cache), "utf-8"); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} |
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