5

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?

Vincent Peres
  • 1,003
  • 1
  • 13
  • 28

1 Answers1

2

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.

mathieugagne
  • 2,465
  • 1
  • 17
  • 18