Skip to content

Commit c4569a5

Browse files
authored
Fix: Race condition between setting value and tags (#192)
1 parent 1c2b811 commit c4569a5

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

packages/nextjs-cache-handler/src/handlers/redis-strings.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ export default function createHandler({
237237
parseBuffersToStrings({ ...cacheHandlerValue, value: valueForStorage });
238238
}
239239

240+
const serializedValue = JSON.stringify({
241+
...cacheHandlerValue,
242+
value: valueForStorage,
243+
});
244+
240245
const setTagsOperation = client
241246
.withAbortSignal(AbortSignal.timeout(timeoutMs))
242247
.hSet(
@@ -251,13 +256,6 @@ export default function createHandler({
251256
.hSet(keyPrefix + sharedTagsTtlKey, key, lifespan.expireAt)
252257
: undefined;
253258

254-
await Promise.all([setTagsOperation, setSharedTtlOperation]);
255-
256-
const serializedValue = JSON.stringify({
257-
...cacheHandlerValue,
258-
value: valueForStorage,
259-
});
260-
261259
switch (keyExpirationStrategy) {
262260
case "EXAT": {
263261
const hasExpireAt = typeof lifespan?.expireAt === "number";
@@ -297,7 +295,14 @@ export default function createHandler({
297295
}
298296
}
299297

300-
await Promise.all([setOperation, expireOperation]);
298+
await Promise.all(
299+
[
300+
setTagsOperation,
301+
setSharedTtlOperation,
302+
setOperation,
303+
expireOperation,
304+
].filter(Boolean),
305+
);
301306
},
302307
async revalidateTag(tag) {
303308
assertClientIsReady();

0 commit comments

Comments
 (0)