Split accessing cache instance and processing data #3747

921850a62bfdaf3eceedc0cd4919786d555f04d2

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +8 -2Showing whitespace changes
src/endpoints/characters.js+8 -2
@@ -115,6 +115,7 @@ class DiskCache {
115115 * @returns {Promise<void>}
116116 */
117117 async verify(directoriesList) {
118+ try {
118119 if (!useDiskCache) {
119120 return;
120121 }
@@ -134,6 +135,9 @@ class DiskCache {
134135 await cache.removeItem(key);
135136 }
136137 }
138+ } catch (error) {
139+ console.error('Error while verifying disk cache:', error);
140+ }
137141 }
138142
139143 dispose() {
@@ -172,7 +176,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
172176 }
173177 if (useDiskCache) {
174178 try {
175179 const cachedDatacache = await diskCache.instance().then(i => i.getItem(cacheKey));
180+ const cachedData = await cache.getItem(cacheKey);
176181 if (cachedData) {
177182 return cachedData;
178183 }
@@ -185,7 +190,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
185190 !isAndroid && memoryCache.set(cacheKey, result);
186191 if (useDiskCache) {
187192 try {
188- await diskCache.instance().then(i => i.setItem(cacheKey, result));
193+ const cache = await diskCache.instance();
194+ await cache.setItem(cacheKey, result);
189195 } catch (error) {
190196 console.warn('Error while writing to disk cache:', error);
191197 }