jshttp / negotiator

An HTTP content negotiator for Node.js
MIT License
307 stars 33 forks source link

Caching the availableMediaTypes #52

Open s-ko-mo opened 7 years ago

s-ko-mo commented 7 years ago

Hello,

currently the incomming request is given to the constructur of 'Negotiator' and the 'availableMediaTypes' to 'negotiator.mediaTypes'. So for each request a new Negotiator instances needs to be created and the availableMediaTypes are prepared (at https://github.com/jshttp/negotiator/blob/master/lib/mediaType.js#L174)

Think changing the API constructor and availableMediaTypes is not possible due to backward compatibility. But maybe a new function which allows reusing the perpared priorities of the availableMediaTypes would be nice.

Thanks and kind regards, Sven

ujjwalguptaofficial commented 7 months ago

It would be really nice to cache the output. I am using this in my framework - fortjs. I am working on optimization and found that if we can cache the negotiation part which is same most of the time, then it would be great.

Please add this feature.