]> dev.renevier.net Git - syp.git/blobdiff - items.php
implements ETag caching for items.php and news.php
[syp.git] / items.php
index c36318379964d0790564a47587ccf7b4416ef27a..e7a97231572a689dc0d4185706e66d2a7aab7b33 100644 (file)
--- a/items.php
+++ b/items.php
@@ -6,9 +6,22 @@ require_once ("./inc/settings.php");
 require_once ("./inc/utils.php");
 require_once ("./inc/db/mysql.php");
 
-function main ($features) {
+function headers_callback ($output) {
+    $etag = md5 ($output);
+    if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && 
+         ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
+         header ("HTTP/1.1 304 Not Modified");
+         exit ();
+    }
 
-    header ("Cache-control: no-cache");
+    header ("Content-type: application/vnd.google-earth.kml+xml");
+    header ("Cache-control: must-revalidate");
+    header (sprintf ("ETag: %s", $etag));
+
+    return $output;
+}
+
+function main ($features) {
 
     echo '<?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://www.opengis.net/kml/2.2">
@@ -70,6 +83,8 @@ try {
 } catch (Exception $e) {
     exit ("server error");
 }
-header ("Content-type: application/vnd.google-earth.kml+xml");
+
+ob_start ("headers_callback");
 main ($features);
+ob_end_flush ()
 ?>