I've got an application written in Sails JS. I want to set caching for my S3 files. I'm not really sure where to start, do I need to do something with my Image GET function? Has anyone had any experience on setting caching for S3 assets?
This Is My Get Function for User Avatars: var SkipperDisk = require('skipper-s3'); var fileAdapter = SkipperDisk( { key: 'xxx', secret: 'xxx+xxx', bucket: 'xxx-xxx' }); fileAdapter.read(user.avatarFd).on('error', function(err) { // return res.serverError(err); return res.redirect('/noavatar.gif'); }).pipe(res); });
Why not enable static website hosting for your S3 bucket? Upload the images to a bucket which can be referenced by images.yourapp.com/unique-image-path
Store the avatar url for each users in database.
Return the image url instead of returning the image.
Doing so might help you to take advantage of client side caching.
While uploading a file to S3, you can set meta data for a file. Set Expires
header to a future date to help caching. You can also set Cache-Control
header. Skipper-s3
supports setting headers for a file while uploading to S3.
https://github.com/balderdashy/skipper#uploading-files-to-s3
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html#RESTObjectPUT-requests