Forums | Mahara Community

Developers /
Profile icon caching is confusing users


anonymous profile picture
Account deleted
Posts: 117

18 July 2010, 20:07

With profile icons (called by user id) being cached for 10 minutes, I'm finding that users are confused when they change their profile icon and it doesn't show the change immediately (unless they refresh the page).  They think that the site isn't working correctly.

Any thoughts on how to get the thumbnails to update immediately when changed?

So far, the only options I have been able to come up with are:

  1. Don't cache user icon thumbnails when called by user id (not a very good option at all)
  2. Don't cache the user's own thumbnails when called by user id. Again, not ideal, but it's better than not caching everyone's.
  3. Eliminate the use of calling thumbnails by user id and only use artefact id. This means having to go through every page that uses user photos and changing the code.

Hopefully, someone has a better idea of how to overcome this issue. Any thoughts?

Gregor Anželj's profile picture
Posts: 349

20 July 2010, 12:40

I was working on an artefact in whic I needed to show thumbnails, which had to be updated immediately (after the edit action...)

This worked / works for me:

//Set no caching for thumbnails...
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

I've include this almost at the beginning of index.php file (which shows the thumbnails) - before calling / showing any of the thumbnails.

Maybe it'll work for you too.

Regards, Gregor

anonymous profile picture
Account deleted
Posts: 117

20 July 2010, 14:05

Unfortunately, that won't work on profile icon thumbnails. Setting those headers on a page prevent caching of the page itself, but any previously cached images (as well as any Javascript and CSS files) are still pulled from the cache unless the user manually refreshes or the filename changes in some way. 

After doing a lot of searching on the Internet, it appears that there is no way to force the reload of a cached image via code. You can change the url by adding a random number or time to the url, but once you use the url without that it goes back to the original cached image. Only the user can force a reload of cached images, javascript, and css before the cache expires.

The only option that seems to work is using the actual artefact id to pull the thumbnails with "profileiconbyid".

3 results