Skip to content

Commit

Permalink
fix: reduce cache time (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 authored Apr 1, 2024
1 parent aba3a97 commit 91adaa3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib/fetch-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ async function getAllTime(pkg: string): Promise<number> {
const url = `https://api.npmjs.org/downloads/range/${start.format(
"YYYY-MM-DD",
)}:${end.format("YYYY-MM-DD")}/${pkg}`;
const res = await get<RangeResponse>(
url,
// if recent 18 months, cache for 1 hour
!start.isAfter(now.subtract(18, "month")),
);
const res = await get<RangeResponse>(url);
downloads += res.downloads.reduce((sum, d) => sum + d.downloads, 0);
start = end;
end = start.add(18, "month");
Expand Down Expand Up @@ -119,10 +115,10 @@ export async function fetchNpmPackage(
};
}

async function get<T = any>(url: string, longCache = true) {
async function get<T = any>(url: string) {
const res = await fetch(url, {
next: {
revalidate: longCache ? 86_400 : 3_600,
revalidate: 3_600,
tags: ["npm"],
},
});
Expand Down

0 comments on commit 91adaa3

Please sign in to comment.