简体   繁体   中英

How can I get Cloudfront to cache the resulting content of a Rails redirect

I have an endpoint in my Rails app where a model id and a couple other parameters form the URL. From there, I look up that model in the DB, and redirect to an image stored on Amazon S3.

Cloudfront is ALWAYS in front of this url, and I really want it to cache the image. Right now, it's caching the redirect, which means it's serving straight from the S3 bucket which is not as efficient.

What can I do? Is there a header I can add to tell Cloudfront to cache the result? Or is there a way I can use Rack::Rewrite but still have access to my ActiveRecord models?

Ultimately the only solution that worked was to change the original S3 URL's. I moved all the logic that computed the URL by model id and other parameters like I described to the S3 image generation. That way my frontend could still generate these urls. Then I set up a Cloudfront URL mapped to the S3 bucket itself and pointed my app to that for image urls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM