file-system-cache
file-system-cache copied to clipboard
Add ability to load use stale cache
Allow passing a parameter to get that allows returning a stale. This can be used to fallback to last know value if needed.
let data = myCache.get(cacheKey);
if (!data ) {
const apiUrl = `https://getdata`;
try {
const response = await axios.get(.....);
data = await response.data;
myCache.set(cacheKey, data );
} catch (error) {
console.error(error);
data = myCache.get(cacheKey, null, true);
if (!data) {
throw error;
}
}
}