cache: use the old response body to prevent memory leaks

This commit is contained in:
Alex Gleason 2024-04-13 14:36:31 -05:00
parent afed0a0b34
commit ff3d8e3f90
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 2 additions and 0 deletions

View File

@ -19,7 +19,9 @@ export const cache = (opts: CacheOpts): MiddlewareHandler => {
await next();
const res = c.res.clone();
if (res.status < 500) {
const old = response;
response = res;
old?.text(); // Prevent memory leaks.
}
return res;
}