vendredi 6 février 2015

Deleting all cached page of the site


Scenario


Mobile and desktop version.

I'm developing a website with a desktop and a mobile version: users can choose to switch version if they want to: javascript will save a cookie telling the desired version and will reload the page appending to its url the value "?nocache=1".

Pages caching.

Pages are cached using the following PHP code:



<?php
$lastModified=filemtime(__FILE__);
$etagFile = md5_file(__FILE__);
if(empty($_GET['nocache'])){
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);
$etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false);
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT");
header("Etag: $etagFile");
header('Cache-Control: public');
if (strtotime($ifModifiedSince)==$lastModified || $etagHeader == $etagFile){
header("HTTP/1.1 304 Not Modified");
exit;
}
}
?>


The problem


The initial condition in the PHP code for the cache will cause the browser load again the page from the server if the user changes version of the site, but all the other pages will remain cached.


My question


Is there any way I can load again all the pages if the desired version of the site is changed?





Aucun commentaire:

Enregistrer un commentaire