mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 06:48:47 +00:00
first public source commit
This commit is contained in:
parent
1a4fbb9d42
commit
3914fee775
65 changed files with 4697 additions and 312 deletions
13
src/utils/cached-fetch.js
Normal file
13
src/utils/cached-fetch.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
import cache from "memory-cache";
|
||||
|
||||
export default async function cachedFetch(url, duration) {
|
||||
const cached = cache.get(url);
|
||||
|
||||
if (cached) {
|
||||
return cached;
|
||||
} else {
|
||||
const data = await fetch(url).then((res) => res.json());
|
||||
cache.put(url, data, duration * 1000 * 60);
|
||||
return data;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue