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 {
115 * @returns {Promise<void>}115 * @returns {Promise<void>}
116 */116 */
117 async verify(directoriesList) {117 async verify(directoriesList) {
118 try {
118 if (!useDiskCache) {119 if (!useDiskCache) {
119 return;120 return;
120 }121 }
@@ -134,6 +135,9 @@ class DiskCache {
134 await cache.removeItem(key);135 await cache.removeItem(key);
135 }136 }
136 }137 }
138 } catch (error) {
139 console.error('Error while verifying disk cache:', error);
140 }
137 }141 }
138142
139 dispose() {143 dispose() {
@@ -172,7 +176,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
172 }176 }
173 if (useDiskCache) {177 if (useDiskCache) {
174 try {178 try {
175 const cachedData = await diskCache.instance().then(i => i.getItem(cacheKey));179 const cache = await diskCache.instance();
180 const cachedData = await cache.getItem(cacheKey);
176 if (cachedData) {181 if (cachedData) {
177 return cachedData;182 return cachedData;
178 }183 }
@@ -185,7 +190,8 @@ async function readCharacterData(inputFile, inputFormat = 'png') {
185 !isAndroid && memoryCache.set(cacheKey, result);190 !isAndroid && memoryCache.set(cacheKey, result);
186 if (useDiskCache) {191 if (useDiskCache) {
187 try {192 try {
188 await diskCache.instance().then(i => i.setItem(cacheKey, result));193 const cache = await diskCache.instance();
194 await cache.setItem(cacheKey, result);
189 } catch (error) {195 } catch (error) {
190 console.warn('Error while writing to disk cache:', error);196 console.warn('Error while writing to disk cache:', error);
191 }197 }