Skip to content

Commit

Permalink
[Fix] Caching in downloadFile (#3484)
Browse files Browse the repository at this point in the history
* Properly cache files downloaded with `downloadFile`

* Bump up the max cache time to 30 days

Somewhat of a band-aid fix; ideally we'd be smarter about this caching
in the first place (for example only re-downloading if the user's
hardware changed)
  • Loading branch information
CommandMC authored Feb 1, 2024
1 parent b261772 commit b7b736b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/backend/utils/inet/downloader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ async function downloadFile(
if (options.maxCache && options.writeToFile) {
const stats = await stat(options.writeToFile).catch(() => null)
if (stats) {
if (stats.birthtime.valueOf() + options.maxCache * 1000 >= Date.now()) {
console.log('Returning cached value for', url)
if (stats.mtimeMs + options.maxCache * 1000 >= Date.now()) {
switch (options.axiosConfig?.responseType) {
case 'text':
return readFile(options.writeToFile, 'utf-8')
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/systeminfo/gpu/pci_ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function getPicIds(): Promise<typeof pciIdsMap | null> {
responseType: 'text'
},
writeToFile: path.join(toolsPath, 'pci.ids'),
maxCache: 7 * DAYS
maxCache: 30 * DAYS
}).catch((error) => error as AxiosError)
if (axios.isAxiosError(pciIdsFile)) return null

Expand Down

0 comments on commit b7b736b

Please sign in to comment.