Problem with image caching

Hello,

I have a little problem with image caching. I have a Student model which contains, for each student, a picture (picture_data for datas and picture_type for the content-type of the picture). As I want to save brandwidth, I followed the tutorial in Peak Obsession for caching pictures. If I test, as the tutorial suggests it, with curl, it's working well. No problems.

But in reality, it's not working well. I have a page to view the student properties (/student/view/:id) with the picture into and a page to edit properties (/student/edit/:id) in which you can upload a new picture. When I update properties, if everything went done normally, I just send a redirect_to to the view. But when I change the picture in the edit page, the picture doesn't update in the view. I have to refresh the page (F5) to get an update of the picture. If I sniff requests made by my browser, after the edit, the picture is not requested. I don't know why.

Every browsers are affected (IE, IE7, FireFox (win and linux), Opera (linux)).

I tried to change the cache headers of the view page without any affects. The only option I have is to send the picture every-time without caching.

Any ideas on this ?

Thanks you very much in advance :wink:

++ Jérôme

Jérôme Loyet wrote:

But when I change the picture in the edit page, the picture doesn't update in the view. I have to refresh the page (F5) to get an update of the picture.

Here's a guess, without understanding that chapter/62:

Hit View Source and look at this line:

<script src="/javascripts/prototype.js?1162442777" type="text/javascript"></script>

That big number, 1162442777, is probably the number of seconds from an epoch to the file modification time of 'prototype.js'.

You need to either figure out what Railsoid system provides such numbers, and turn it on for images, or you need to rewrite it, with File.stat().mtime.to_i (IIRC).

(And I would use the file time of your image on your server, not a database record time...)

Then when the file time changes, the page will contain a different number, and the browser will know to re-fetch the image.

Every browsers are affected (IE, IE7, FireFox (win and linux), Opera (linux)).

That's because caching and not re-loading images is about the most basic and common optimization they can perform.