express-processimage icon indicating copy to clipboard operation
express-processimage copied to clipboard

SharpCache option in express-processimage

Open ramasamymohan opened this issue 9 years ago • 3 comments

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.

ramasamymohan avatar Aug 10 '16 12:08 ramasamymohan

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?

papandreou avatar Aug 10 '16 14:08 papandreou

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.

ramasamymohan avatar Aug 10 '16 15:08 ramasamymohan

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.

papandreou avatar Aug 10 '16 22:08 papandreou