Skip to content

Commit

Permalink
More /projects cache tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Mar 24, 2024
1 parent e86138d commit 2725d1d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,15 @@ const getProjectMeta = async (projectId) => {
// api.scratch.mit.edu has Cache-Control: max-age=240 and the tokens have a timestamp
// that 300 seconds into the future. However that timestamp is consistently wrong,
// so we shouldn't wait for it to be close to expiry.
return unixTimestamp - SECOND * 180;
return unixTimestamp - SECOND * 120;
}, () => {
return apiQueue.queuePromise(`https://api.scratch.mit.edu/projects/${projectId}/?`);
// Send along a slightly random query string so we're more likely to get an uncached token if
// we just evicted an old cache entry.
// We're not going to send a traditional cachebuster like ?nocache=${Date.now()} because they've
// throttled those really bad in the past.
const ENDINGS = ['', '?', '/', '/?'];
const ending = ENDINGS[Math.floor(Math.random() * ENDINGS.length)];
return apiQueue.queuePromise(`https://api.scratch.mit.edu/projects/${projectId}${ending}`);
});
};

Expand Down

0 comments on commit 2725d1d

Please sign in to comment.