Skip to content

Commit 59598d0

Browse files
committed
fix: more defensive cache hit logic
1 parent 31d2d8b commit 59598d0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/nuxt/src/runtime/plugins/storage.server.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ const CACHED_FN_HANDLERS_RE = /^nitro:(functions|handlers):/i;
253253
* First we check if the key matches the `defineCachedFunction` or `defineCachedEventHandler` key patterns, and if so we check the cached value.
254254
*/
255255
function isCacheHit(key: string, value: unknown): boolean {
256-
const isEmpty = isEmptyValue(value);
257-
// Empty value means no cache hit either way
258-
// Or if key doesn't match the cached function or handler patterns, we can return the empty value check
259-
if (isEmpty || !CACHED_FN_HANDLERS_RE.test(key)) {
260-
return !isEmpty;
261-
}
262-
263256
try {
257+
const isEmpty = isEmptyValue(value);
258+
// Empty value means no cache hit either way
259+
// Or if key doesn't match the cached function or handler patterns, we can return the empty value check
260+
if (isEmpty || !CACHED_FN_HANDLERS_RE.test(key)) {
261+
return !isEmpty;
262+
}
263+
264264
return validateCacheEntry(key, JSON.parse(String(value)) as CacheEntry);
265265
} catch (error) {
266266
// this is a best effort, so we return false if we can't validate the cache entry

0 commit comments

Comments
 (0)