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

View file

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