Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control the cache with carrierwave on Rackspace cloud storage?

Users can upload avatars on my website. This can change quiet often. I need a strict url that will not change as the url can be displayed in some cached part of the website. I have tried to set on my Rails application the following fog attributes to disable caching, but I don't get any result out of it...

config.fog_attributes = {'Cache-Control' => 'max-age=1', 'Expires' => 1.day.ago.httpdate}

Right now, when a user is uploading a new avatar, it can take hours before the previous one disappear from the cache.

Here is an example of a user avatar url on Rackspace cloud storage:

https://c28078.ssl.cf3.rackcdn.com/user/1/small_profile_image.jpg

How can I be sure that an updated avatar will be displayed instantly without any cache trouble?

like image 937
Vincent Peres Avatar asked Nov 05 '22 04:11

Vincent Peres


1 Answers

If you have an Avatar model, your URLs would change for every new avatar uploaded. You could also keep a history of avatar for a particular user. URLs would then look like this:

https://c28078.ssl.cf3.rackcdn.com/avatar/482/small_profile_image.jpg

No more caching problem. Cache block for a user updates when you change avatar. Avatar urls are unique.

like image 96
mathieugagne Avatar answered Nov 15 '22 06:11

mathieugagne