mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
first public source commit
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user