Jump to content

Redirect after deletion of comment and timestamp update = no cache revalidation


SuperBlue

Recommended Posts

I'm having a problem with a bit of code, which works for everything else, but just doesn't work when used for deletion of comments.

 

The relevant code:

mysql_query("UPDATE $table SET LastEdited = '$time' WHERE PID = '$ID'", $Connection) or die(mysql_error());
header('Location: /'. $URL;

This works, the resource is getting updated. What doesn't work is the revalidation after the redirect.

 

The code I'm using for caching is:

  header("Cache-Control: must-revalidate");
  header("Last-Modified: ".gmdate("D, d M Y H:i:s", $Header['LTIME'])." GMT");
  header("Etag: $etag");
  header('Content-type: text/html; charset=UTF-8');

if ((@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $Header['LTIME']) && ( 
    trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { 
    header("HTTP/1.1 304 Not Modified");
    exit;
}

 

Its the exact same code used when posting comments on the site, aside from the query of cause. What i don't get, is why i have to hit update in my browser, to get it to re-validate.

 

The $etag will only be updated if the sites source have been changed.

  • 1 month later...

Ok. I'm pretty sure i have this problem solved now.

 

Turned out the location header alone was redirecting trough a 302 response, rather than a 303.

After i added the 303 thing, everything now appears to behave as expected.

 

If the server just responds with a 302, it appears that the browser just re-loads the page from the cache, without performing the re-validation that the server originally requested for the given page.

When using a 303 however, it would seem that it properly re-checks the cache headers of the page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.