Saturday 3 June 2017

Defer Node.js HTTP requests if similar work already being done

I'm making a service which retrieves a photograph from a remote host and does some processing before passing it on to the client. It caches the retrieved source photo locally to avoid retrieving it again later on.

However, if there are several requests in rapid succession, the source image will not yet have been saved locally, and unnecessary retrievals are performed.

What is a nice approach to defer the incoming requests until the source image is cached, provided it's already currently being retrieved?

I'm currently using Node.js streams all the way from the inbound request stream, passing it through my caching and transformation logic, passing it to the outbound stream.



via sune

No comments:

Post a Comment