papandreou / express-processimage

Express middleware that processes served images according to the query string
BSD 3-Clause "New" or "Revised" License
56 stars 18 forks source link

SharpCache option in express-processimage #17

Open ramasamymohan opened 8 years ago

ramasamymohan commented 8 years ago

I was trying to use sharpCache option to cache images,

app.use(processImage({ root: 'public', sharpCache: { items: 200,files: 30 } }));

If sharpCache option is not given I think it should take default sharp cache option. Is sharpCache option working?

Everytime, when an image is processed through url query string it uses more cpu. If it can cache it in file system, I believe it can process image faster. Any idea?

Thank you.

papandreou commented 8 years ago

Hi!

As you've found, the sharpCache option maps directly to http://sharp.dimens.io/en/stable/api/#sharpcacheoptions -- but unfortunately libvips' operation cache only applies to files loaded from disc, which doesn't happen with express-processimage, because it uses the stream-based input. In cases where express-processimage sits directly on top of eg. the static middleware, that's probably a bit silly, especially if you'd like for the caching to work :)

We could consider introducing a mode where express-processimage takes control of loading the file from disc and hands the file name to the image libs, thus enabling the use of the sharp cache. Would that fix your use case?

ramasamymohan commented 8 years ago

I appreciate your quick reply. It would be great if a mode can enable sharp cache and if express-processimage could take control to load the image from disc.

Thank you.

papandreou commented 8 years ago

Okay, thanks. I might look into implementing that when I get around to integrate https://github.com/papandreou/impro -- I can't make any guarantees about when that will happen, though.