diff Sitemap.inc @ 99:d98e315308cd

Improved caching of flag and sitemap.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Sun, 14 Sep 2014 21:11:27 +0200
parents f2d52fed708c
children a5c37e845d7c
line wrap: on
line diff
--- a/Sitemap.inc	Fri Oct 19 01:36:22 2012 +0200
+++ b/Sitemap.inc	Sun Sep 14 21:11:27 2014 +0200
@@ -7,8 +7,20 @@
 $cache->includeOnce('Http.inc', $baseDir);
 $cache->includeOnce('Page.inc', $baseDir);
 $cache->includeOnce('common-functions.inc', $baseDir);
+$cache->includeOnce('CacheTimeCheck.inc', $baseDir);
 /// @endcond
 
+class SimpleCache extends Cache {
+  private $time;
+
+  function __construct($time = 0) {
+    $this->time = $time;
+  }
+  function getNewest() {
+    return $this->time;
+  }
+};
+
 function cmp_length_lex($a, $b)
 {
   if ($a == $b) {
@@ -41,11 +53,15 @@
     $this->master->load($path);
 
     $this->options = new Options($this->master);
+    $this->lastmod=0;
   }
 
   function cacheCheck()
   {
-    return false;
+    if ($this->lastmod == 0)
+      return Cacheable::UNDETERMINED;
+    else
+      return Cacheable::YES;
   }
 
   function mayValidate()
@@ -125,6 +141,9 @@
 
       if ($n == StatusCodes::HTTP_OK) {
 	$lastmod = strtotime($lastmod);
+	if ($lastmod > $this->lastmod) {
+	  $this->lastmod = $lastmod;
+	}
 	$lastmod = date(DateTime::W3C, $lastmod);
 
 	$out .= "<url>\n";
@@ -137,6 +156,9 @@
     $out .= '</urlset>';
 
     $res = new PageContent($out);
+    $cache=new SimpleCache($this->lastmod);
+    $cache->setMaxAge(86400);
+    $this->setCache($cache);
     $res->setHeader('Content-type', 'application/xml');
     return $res;
   }