apicache icon indicating copy to clipboard operation
apicache copied to clipboard

Problem caching redirect responses

Open marcbc opened this issue 7 years ago • 2 comments

Hi, not sure if I'm using the module as expected, but I wanted to cache a redirect response (res.redirect(URL)), because this redirection is computed from some DB values and it's something I'd like to avoid doing every time.

I'm getting an exception from apicache.js:143 , a..

TypeError: "list" argument must be an Array of Buffers
   at Function.Buffer.concat (buffer.js:314:13)
   at accumulateContent (.../node_modules/apicache/src/apicache.js:143:40)

This is because the res.end() for the redirect is accumulating a String, and later on the res.write() is triggering a Buffer.concat([oldContent, content], ...) were oldContent is String and content is Buffer (would need to be a concat([Buffer, Buffer]), as it happens with regular res.send() responses).

Is there any workaround for this? Would it make sense to convert contents always to Buffers to avoid running into this issues?

thanks a congrats for the great work!

marcbc avatar Jun 15 '18 12:06 marcbc

Not sure but I think there is a problem with nodejs < 8.x version. Not sure but apicache throw this error on my setup only in version 6.x not with nodejs 8.x

HugoPoi avatar Aug 22 '18 09:08 HugoPoi

Might be fixed with https://github.com/kwhitley/apicache/commit/44c981bf156cee6e4773de042bb65db8dcce35bf available on npm in v1.2.6.

apascal avatar Mar 21 '19 19:03 apascal