Split accessing cache instance and processing data

#3747
This commit is contained in:
Cohee
2025-03-23 23:09:21 +02:00
parent 4048a0a09a
commit 921850a62b

View File

@@ -115,6 +115,7 @@ class DiskCache {
* @returns {Promise<void>}
*/
async verify(directoriesList) {
try {
if (!useDiskCache) {
return;
}
@@ -134,6 +135,9 @@ class DiskCache {
await cache.removeItem(key);
}
}
} catch (error) {
console.error('Error while verifying disk cache:', error);
}
}
dispose() {
@@ -172,7 +176,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
}
if (useDiskCache) {
try {
const cachedData = await diskCache.instance().then(i => i.getItem(cacheKey));
const cache = await diskCache.instance();
const cachedData = await cache.getItem(cacheKey);
if (cachedData) {
return cachedData;
}
@@ -185,7 +190,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
!isAndroid && memoryCache.set(cacheKey, result);
if (useDiskCache) {
try {
await diskCache.instance().then(i => i.setItem(cacheKey, result));
const cache = await diskCache.instance();
await cache.setItem(cacheKey, result);
} catch (error) {
console.warn('Error while writing to disk cache:', error);
}