Public access cache control

Hello,
I use storj to store images using for a website. I am using the public url of the image directly as “src” in my img tag.
The issue is that the image does not cached so it makes lots of calls to storj.
Can I add cache control to storj endpoint?
I know I can setup a proxy but I prefer not to.
Thanks

Hello @amit,
Welcome to the forum!

If you use our linksharing service, then - no, because cache can be enabled only server-side. You need to use a proxy in this case. However, sometimes the web-engine allows to cache remote media content, you need to consult with the documentation for your web-server.
The other option would be to host your own S3 gateway with cache enabled, however, you likely will need to run a proxy anyway to make these URLs publicly available.
The third option is to configure rclone and mount a bucket to the local folder with rclone mount command and cache enabled.

1 Like

If you want to set the cache control header the Linksharing service responds with, it’s possible to do that by setting cache-control metadata when uploading either by uplink or the S3 gateway.

e.g.

aws s3 cp /tmp/myfile.mp4 s3://myfiles --cache-control="public, max-age=604800"
uplink cp /tmp/myfile.mp4 sj://myfiles --metadata '{"cache-control":"public, max-age=604800"
4 Likes

how that will work? Objects will not be downloaded from the Storj network when you access them within TTL?

Yes, the browser would send If-Modified-Since header when making a request to the file, then Linksharing does a download request to the Satellite (but not start the download yet). The modified date in the metadata from the Satellite is checked against that header to determine if a 304 should be the response indicating the browser to use the cached copy.

It would be better using a dedicated cache/proxy/CDN of some kind so there is not even a request to Linksharing, and in-turn Satellite. But this simple browser caching could be better than nothing for static assets with a custom domain on Linksharing though.

2 Likes