Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7fb152

Browse files
committed
refactor(isr): standardize terminology from 'route' to 'cacheKey'
1 parent 6c7670b commit f7fb152

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

libs/isr/server/src/cache-handlers/filesystem-cache-handler.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class FileSystemCacheHandler extends CacheHandler {
8989
})
9090
.catch((err) => {
9191
reject(
92-
`Error: 💥 Cannot read cache file for route ${cacheKey}: ${cachedMeta.htmlFilePath}, ${err}`,
92+
`Error: 💥 Cannot read cache file for cacheKey ${cacheKey}: ${cachedMeta.htmlFilePath}, ${err}`,
9393
);
9494
});
9595
} else {
@@ -104,23 +104,23 @@ export class FileSystemCacheHandler extends CacheHandler {
104104

105105
delete(cacheKey: string): Promise<boolean> {
106106
return new Promise((resolve, reject) => {
107-
const cacheMeta = this.cache.get(cacheKey);
107+
const cachedMeta = this.cache.get(cacheKey);
108108

109-
if (cacheMeta) {
110-
fs.unlink(cacheMeta.htmlFilePath, (err) => {
109+
if (cachedMeta) {
110+
fs.unlink(cachedMeta.htmlFilePath, (err) => {
111111
if (err) {
112112
reject(
113-
'Error: 💥 Cannot delete cache file for route ' +
113+
'Error: 💥 Cannot delete cache file for cacheKey ' +
114114
cacheKey +
115-
`: ${cacheMeta.htmlFilePath}`,
115+
`: ${cachedMeta.htmlFilePath}`,
116116
);
117117
} else {
118118
this.cache.delete(cacheKey);
119119
resolve(true);
120120
}
121121
});
122122
} else {
123-
reject(`Error: 💥 CacheKey: ${cacheKey} is not cached.`);
123+
reject(`Error: 💥 cacheKey: ${cacheKey} is not cached.`);
124124
}
125125
});
126126
}
@@ -184,7 +184,7 @@ export class FileSystemCacheHandler extends CacheHandler {
184184
isBuffer: false,
185185
});
186186

187-
console.log('The request was stored in cache! Route: ', cacheKey);
187+
console.log('The request was stored in cache! cacheKey: ', cacheKey);
188188
}
189189
}
190190

@@ -222,7 +222,9 @@ export class FileSystemCacheHandler extends CacheHandler {
222222
}
223223
}
224224
} catch (err) {
225-
console.error('ERROR! 💥 ! Cannot read folder: ' + folderPath);
225+
console.error(
226+
`ERROR! 💥 ! Cannot read folder: ${folderPath}, err: ${err instanceof Error ? err.message : ''}`,
227+
);
226228
}
227229

228230
for (const { path } of pathsToCache) {
@@ -316,7 +318,9 @@ function findIndexHtmlFilesRecursively(
316318
});
317319
} catch (err) {
318320
// If an error occurs, log an error message and return an empty array
319-
console.error('ERROR! 💥 ! Cannot read folder: ' + path);
321+
console.error(
322+
`ERROR! 💥 ! Cannot read folder: ${path}, err: ${err instanceof Error ? err.message : ''}`,
323+
);
320324
return [];
321325
}
322326

@@ -345,22 +349,22 @@ function getFileFullPath(fileName: string, cacheFolderPath: string): string {
345349
}
346350

347351
/**
348-
* This function takes a string parameter 'route' and replaces all '/' characters in it with '__' and returns the modified string.
352+
* This function takes a string parameter 'cacheKey' and replaces all '/' characters in it with '__' and returns the modified string.
349353
*
350354
* @internal
351-
* @param {string} cacheKey - The string representing the route to be converted into a file name.
355+
* @param {string} cacheKey - The string representing the cacheKey to be converted into a file name.
352356
* @returns {string} The modified string representing the file name obtained by replacing '/' characters with '__'.
353357
*/
354358
export function convertCacheKeyToFileName(cacheKey: string): string {
355-
// replace all occurrences of '/' character in the 'route' string with '__' using regular expression
359+
// replace all occurrences of '/' character in the 'cacheKey' string with '__' using regular expression
356360
return cacheKey
357361
.replace(new RegExp('/', 'g'), '__')
358362
.replace(new RegExp('\\?', 'g'), '++');
359363
}
360364

361365
/**
362366
* This function takes a string parameter 'fileName' and replaces all '__' strings in it with '/' and returns the modified string.
363-
* @param fileName - The string representing the file name to be converted into a route.
367+
* @param fileName - The string representing the file name to be converted into a cacheKey.
364368
*/
365369
export function convertFileNameToCacheKey(fileName: string): string {
366370
// replace all occurrences of '__' string in the 'fileName' string with '/' using regular expression

0 commit comments

Comments
 (0)