-
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.
Merge pull request #9 from vladaviedov/caching
Caching
- Loading branch information
Showing
7 changed files
with
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Release | ||
node_modules/ | ||
|
||
# Dev | ||
.vscode/ | ||
*.svg | ||
data.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
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,25 @@ | ||
import { readFileSync, writeFileSync, existsSync } from "fs"; | ||
import { config } from "./config.js"; | ||
|
||
export const retrieveStorage = () => { | ||
// Check if store exists | ||
if (!existsSync(config.storeFile)) { | ||
return null; | ||
} | ||
|
||
// Read from store | ||
const rawData = readFileSync(config.storeFile, { encoding: "utf-8" }); | ||
return JSON.parse(rawData); | ||
}; | ||
|
||
export const updateStorage = data => { | ||
// Wrapper to store timestamp | ||
const dataStorage = { | ||
analysis: data, | ||
timestamp: new Date().toISOString() | ||
}; | ||
|
||
// Write to store | ||
const jsonData = JSON.stringify(dataStorage); | ||
writeFileSync(config.storeFile, jsonData, { encoding: "utf-8" }); | ||
}; |
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
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