Skip to content

Commit f8299d9

Browse files
committed
enforce cache writing order
1 parent 125b19e commit f8299d9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const middleware = (opts) => async (req, res, next) => {
7070
}
7171
}
7272

73-
onEnd(res, (payload) => {
73+
onEnd(res, async (payload) => {
7474
if (payload.status === 304) return
7575

7676
if (payload.headers[X_CACHE_EXPIRE]) {
@@ -109,10 +109,10 @@ const middleware = (opts) => async (req, res, next) => {
109109
}
110110

111111
// cache response data
112-
mcache.set(req.cacheKey + DATA_POSTFIX, JSON.stringify({ data: payload.data }), { ttl })
112+
await mcache.set(req.cacheKey + DATA_POSTFIX, JSON.stringify({ data: payload.data }), { ttl })
113113
delete payload.data
114114
// cache response metadata
115-
mcache.set(req.cacheKey, JSON.stringify(payload), { ttl })
115+
await mcache.set(req.cacheKey, JSON.stringify(payload), { ttl })
116116
}
117117
})
118118

0 commit comments

Comments
 (0)