refresh archive folder after import

This commit is contained in:
Jan Prochazka
2020-11-15 20:46:42 +01:00
parent 801bf05a31
commit 72776f3297
3 changed files with 30 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ import _ from 'lodash';
import axios from './axios';
import useSocket from './SocketProvider';
import stableStringify from 'json-stable-stringify';
import { getCachedPromise, cacheGet, cacheSet } from './cache';
import { getCachedPromise, cacheGet, cacheSet, cacheClean } from './cache';
import getAsArray from './getAsArray';
export default function useFetch({
@@ -43,9 +43,17 @@ export default function useFetch({
if (fromCache) {
setValue([fromCache, loadedIndicators]);
} else {
const res = await getCachedPromise(cacheKey, doLoad);
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
try {
const res = await getCachedPromise(cacheKey, doLoad);
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
} catch (err) {
console.error('Error when using cached promise', err);
cacheClean(cacheKey);
const res = await doLoad();
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
}
}
} else {
const res = await doLoad();