@@ -170,22 +170,22 @@ type CommonNeshCacheOptions<Arguments extends unknown[], Result> = Omit<
170170 *
171171 * @param callback - The callback function to be cached.
172172 *
173- * @param options - An object containing options for the cache.
173+ * @param commonOptions - An object containing options for the cache.
174174 *
175- * @param options .tags - An array of tags to associate with the cached result.
175+ * @param commonOptions .tags - An array of tags to associate with the cached result.
176176 * Tags are used to revalidate the cache using the `revalidateTag` function.
177177 *
178- * @param options .revalidate - The revalidation interval in seconds.
178+ * @param commonOptions .revalidate - The revalidation interval in seconds.
179179 * Must be a positive integer or `false` to disable revalidation.
180180 * Defaults to `export const revalidate = time;` in the current route.
181181 *
182- * @param options .argumentsSerializer - A function that serializes the arguments passed to the callback function.
182+ * @param commonOptions .argumentsSerializer - A function that serializes the arguments passed to the callback function.
183183 * Use it to create a cache key. Defaults to `JSON.stringify(args)`.
184184 *
185- * @param options .resultSerializer - A function that serializes the result of the callback function.
185+ * @param commonOptions .resultSerializer - A function that serializes the result of the callback function.
186186 * Defaults to `Buffer.from(JSON.stringify(data)).toString('base64')`.
187187 *
188- * @param options .resultDeserializer - A function that deserializes the string representation of the result of the callback function.
188+ * @param commonOptions .resultDeserializer - A function that deserializes the string representation of the result of the callback function.
189189 * Defaults to `JSON.parse(Buffer.from(data, 'base64').toString('utf-8'))`.
190190 *
191191 * @returns The callback wrapped in a caching function.
@@ -269,6 +269,8 @@ export function neshCache<Arguments extends unknown[], Result extends Promise<un
269269
270270 let cacheData : IncrementalCacheEntry | null = null ;
271271
272+ let data : Result ;
273+
272274 try {
273275 cacheData = await store . incrementalCache . get ( key , {
274276 revalidate,
@@ -278,21 +280,13 @@ export function neshCache<Arguments extends unknown[], Result extends Promise<un
278280 fetchIdx,
279281 fetchUrl : 'neshCache' ,
280282 } ) ;
281- } catch ( error ) {
282- await handleUnlock ( ) ;
283283
284- throw error ;
285- }
284+ if ( cacheData ?. value ?. kind === 'FETCH' && cacheData . isStale === false ) {
285+ await handleUnlock ( ) ;
286286
287- if ( cacheData ?. value ?. kind === 'FETCH' && cacheData . isStale === false ) {
288- await handleUnlock ( ) ;
289-
290- return resultDeserializer ( cacheData . value . data . body ) ;
291- }
292-
293- let data : Result ;
287+ return resultDeserializer ( cacheData . value . data . body ) ;
288+ }
294289
295- try {
296290 data = await staticGenerationAsyncStorage . run (
297291 {
298292 ...store ,
@@ -304,7 +298,6 @@ export function neshCache<Arguments extends unknown[], Result extends Promise<un
304298 ...args ,
305299 ) ;
306300 } catch ( error ) {
307- // biome-ignore lint/complexity/noUselessCatch: we need to rethrow the error
308301 throw error ;
309302 } finally {
310303 await handleUnlock ( ) ;
0 commit comments