mirror of
https://github.com/zyachel/quetre.git
synced 2025-04-04 21:47:38 +03:00
feat: implement caching of api responses
should help a bit in not getting rate-limited
This commit is contained in:
parent
a3b7f276cc
commit
175878dba9
10 changed files with 195 additions and 35 deletions
35
utils/cacheKeys.js
Normal file
35
utils/cacheKeys.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
////////////////////////////////////////////////////////
|
||||
// LOCAL HELPERS
|
||||
////////////////////////////////////////////////////////
|
||||
const getLang = urlObj => urlObj.searchParams.get('lang') || 'en';
|
||||
const formatSlug = (slug, charToRemove) =>
|
||||
slug.replace(charToRemove, '').toLowerCase();
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// EXPORTS
|
||||
////////////////////////////////////////////////////////
|
||||
export const searchKey = urlObj => {
|
||||
const slug = formatSlug(urlObj.search, '?');
|
||||
return `search:${slug}`;
|
||||
};
|
||||
|
||||
export const answersKey = urlObj => {
|
||||
const slug = formatSlug(urlObj.pathname, '/');
|
||||
const lang = getLang(urlObj);
|
||||
|
||||
return `answers:${slug}&lang=${lang}`;
|
||||
};
|
||||
|
||||
export const topicKey = urlObj => {
|
||||
const slug = formatSlug(urlObj.pathname, '/topic/');
|
||||
const lang = getLang(urlObj);
|
||||
|
||||
return `topic:${slug}&lang=${lang}`;
|
||||
};
|
||||
|
||||
export const profileKey = urlObj => {
|
||||
const slug = formatSlug(urlObj.pathname, '/profile/');
|
||||
const lang = getLang(urlObj);
|
||||
|
||||
return `profile:${slug}&lang=${lang}`;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue