Skip To Navigation

Culture Cache

Something I should have done ages ago: setting up my RSS feeds so readers can cache them (Stuff 1, 2, 3). First step: adding an Entity Tag to responses, uniquely identifying its content and saving bandwidth by not serving the same file to the same place twice. After generating the feed and putting the XML into $thisnode->allcode, I used this:

// generate etag
$etag = md5($thisnode->allcode);
header('ETag: "'.$etag.'"');

// look at if-none-match
   $httpinm = $_SERVER['HTTP_IF_NONE_MATCH'];
   $httpinm = get_magic_quotes_gpc() ? stripslashes($httpinm) : $httpinm;

   $matches = array();
   preg_match_all('#"([^"]*)"#', $httpinm, $matches);

   foreach($matches[1] as $cachedetag)
      if($etag == $cachedetag) // clear $thisnode->allcode and send 304
         $thisnode->allcode = '';
         header('HTTP/1.x 304 Not Modified');

// Note: In the case of this site, RdMise will output the content
// with the correct Content-Type header later on.

Seems to work so far, I'll just test it a bit more before putting it "live"...

⇐10 Jul 2005 - ChatZilla Update / 08 Jul 2005 - "Terrorism, plain and simple."⇒


Feedback is closed. Feel free to contact me privately.