Add error handling to accessing disk cache

Fixes #3747
This commit is contained in:
Cohee
2025-03-23 21:05:36 +02:00
parent 9717259776
commit 2af33a9e18

View File

@@ -171,16 +171,24 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
return memoryCache.get(cacheKey);
}
if (useDiskCache) {
const cachedData = await diskCache.instance().then(i => i.getItem(cacheKey));
if (cachedData) {
return cachedData;
try {
const cachedData = await diskCache.instance().then(i => i.getItem(cacheKey));
if (cachedData) {
return cachedData;
}
} catch (error) {
console.warn('Error while reading from disk cache:', error);
}
}
const result = await parse(inputFile, inputFormat);
!isAndroid && memoryCache.set(cacheKey, result);
if (useDiskCache) {
await diskCache.instance().then(i => i.setItem(cacheKey, result));
try {
await diskCache.instance().then(i => i.setItem(cacheKey, result));
} catch (error) {
console.warn('Error while writing to disk cache:', error);
}
}
return result;
}