Skip to content

Commit

Permalink
refactor: simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 10, 2024
1 parent a4e4089 commit 4c644b4
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/runtime/internal/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,12 @@ export function defineCachedFunction<T, ArgsT extends unknown[] = any[]>(
delete pending[key];
const promise =
validate(entry) === false
? useStorage()
.removeItem(cacheKey)
.catch((error) => {
console.error(`[nitro] [cache] Cache write error.`, error);
useNitroApp().captureError(error, { event, tags: ["cache"] });
})
: useStorage()
.setItem(cacheKey, entry)
.catch((error) => {
console.error(`[nitro] [cache] Cache write error.`, error);
useNitroApp().captureError(error, { event, tags: ["cache"] });
});
? useStorage().removeItem(cacheKey)
: useStorage().setItem(cacheKey, entry);
promise.catch((error) => {
console.error(`[nitro] [cache] Cache update error.`, error);
useNitroApp().captureError(error, { event, tags: ["cache"] });
});
if (event?.waitUntil) {
event.waitUntil(promise);
}
Expand Down

0 comments on commit 4c644b4

Please sign in to comment.