From 7131b6688badc1c1e9685aba4b222f147bc1df83 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sat, 6 Aug 2005 17:58:57 +0200
Subject: [PATCH] caching for feeds

This patch adds caching for XML/ATOM feeds. This is most useful for the
default feed (linked from the footer and HTML meta header) as this is
usually the most used one.

The cache is invalidated if a change was made (by checking the the
filemtime of the changelog). A 5 minute settling time is used to avoid
invalidating the cache too often when the wiki changes rapidly.

darcs-hash:20050806155857-7ad00-5b9cb05b42d67c3f23f0358676735038b9f59664.gz
---
 feed.php | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/feed.php b/feed.php
index c241a610f..521f9b968 100644
--- a/feed.php
+++ b/feed.php
@@ -13,14 +13,7 @@
   require_once(DOKU_INC.'inc/feedcreator.class.php');
   require_once(DOKU_INC.'inc/auth.php');
 
-  //set auth header for login FIXME: is this used anymore???
-  if($_REQUEST['login'] && !isset($_SERVER['PHP_AUTH_USER'])){
-    header('WWW-Authenticate: Basic realm="'.$conf['title'].'"');
-    header('HTTP/1.0 401 Unauthorized');
-    auth_logoff();
-  }
-
-  //close sesseion
+  //close session
   session_write_close();
 
 
@@ -44,13 +37,20 @@
        $type = 'RSS1.0';
   }
 
-  //some defaults for the feed
-  $CACHEGROUP = 'feed';
-  $conf['typography'] = false;
-  $conf['canonical']  = true;
-  $parser['toc']      = false;
+	// the feed is dynamic - we need a cache for each combo
+  // (but most people just use the default feed so it's still effective)
+	$cache = getCacheName($num.$type.$mode.$ns.$ltype.$_SERVER['REMOTE_USER'],'.feed');
+
+	// check cacheage and deliver if nothing has changed since last
+  // time (with 5 minutes settletime)
+	$cmod = @filemtime($cache); // 0 if not exists
+	if($cmod && ($cmod+(5*60) >= @filemtime($conf['changelog']))){
+  	header('Content-Type: application/xml; charset=utf-8');
+		print io_readFile($cache);
+		exit;
+  }
 
-#  $rss = new UniversalFeedCreator();
+	// create new feed
   $rss = new DokuWikiFeedCreator();
   $rss->title = $conf['title'];
   $rss->link  = DOKU_URL;
@@ -69,8 +69,14 @@
     rssRecentChanges($rss,$num,$ltype);
   }
 
+  $feed = $rss->createFeed($type,'utf-8');
+	
+  // save cachefile
+	io_saveFile($cache,$feed);
+
+	// finally deliver
   header('Content-Type: application/xml; charset=utf-8');
-  print $rss->createFeed($type,'utf-8');
+  print $feed;
 
 // ---------------------------------------------------------------- //
 
-- 
GitLab