file-system-cache icon indicating copy to clipboard operation
file-system-cache copied to clipboard

Add ability to load use stale cache

Open wizhippo opened this issue 1 year ago • 0 comments

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;
        }
    }
}

wizhippo avatar Sep 08 '23 20:09 wizhippo