Refactor cache entry removal to use Set for removalQueue
| @@ -50,7 +50,7 @@ const diskCache = { | |||
| 50 | */ | 50 | */ |
| 51 | _removeCacheEntries: async function() { | 51 | _removeCacheEntries: async function() { |
| 52 | try { | 52 | try { |
| 53 | if (!useDiskCache || this.removalQueue.length === 0) { | 53 | if (!useDiskCache || this.removalQueue.size === 0) { |
| 54 | return; | 54 | return; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| @@ -62,7 +62,7 @@ const diskCache = { | |||
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | console.info('Removed cache entries:', this.removalQueue); | 64 | console.info('Removed cache entries:', this.removalQueue); |
| 65 | this.removalQueue = []; | 65 | this.removalQueue.clear(); |
| 66 | } catch (error) { | 66 | } catch (error) { |
| 67 | console.error('Error while removing cache entries:', error); | 67 | console.error('Error while removing cache entries:', error); |
| 68 | } | 68 | } |
| @@ -84,9 +84,9 @@ const diskCache = { | |||
| 84 | }, | 84 | }, |
| 85 | /** | 85 | /** |
| 86 | * Queue for removal of cache entries. | 86 | * Queue for removal of cache entries. |
| 87 | * @type {string[]} | 87 | * @type {Set<string>} |
| 88 | */ | 88 | */ |
| 89 | removalQueue: [], | 89 | removalQueue: new Set(), |
| 90 | }; | 90 | }; |
| 91 | 91 | ||
| 92 | /** | 92 | /** |
| @@ -166,7 +166,7 @@ async function writeCharacterData(inputFile, data, outputFile, request, crop = u | |||
| 166 | } | 166 | } |
| 167 | } | 167 | } |
| 168 | if (useDiskCache && !Buffer.isBuffer(inputFile)) { | 168 | if (useDiskCache && !Buffer.isBuffer(inputFile)) { |
| 169 | diskCache.removalQueue.push(inputFile); | 169 | diskCache.removalQueue.add(inputFile); |
| 170 | } | 170 | } |
| 171 | /** | 171 | /** |
| 172 | * Read the image, resize, and save it as a PNG into the buffer. | 172 | * Read the image, resize, and save it as a PNG into the buffer. |