Right now files uploaded via ActiveStorage with the GCS Service default to

cache-control:
private,max-age=0

This is particularly problematic for Google Cloud CDN, since it only caches 
assets that are public: 
https://cloud.google.com/cdn/docs/troubleshooting

Cloud CDN caches only responses that are marked public and specify an 
> expiration time or maximum age. This information is conveyed in HTTP 
> response headers. If responses for a URL aren't being cached, check which 
> HTTP headers are being returned for that URL.



ActiveStorage's architecture involves a 302 redirect to the underlying 
asset. Without a CDN for the GCS scenario, the performance implications of 
a highly trafficked site to also have to redirect wouldn't be stellar. But 
perhaps this is only a GCS problem, since I know AWS will cache content 
regardless of the cache-control header.

My proposed solution for this is to allow a developer to configure headers 
in the config/storage.yml on a per service basis:

google:
>   service: GCS
>   project: someproject
>   keyfile: credentials.json
>   bucket: bucket-of-assets
>   object_options:
>     cache_control: public, max-age=31556926



Ultimately, I believe developers will occasionally need a way to set 
headers on the files uploaded via ActiveStorage by the non Disk services. I 
would love to hear better alternatives if there are any.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to