Mercurial > SimpleWebPresenter
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 98:f2d52fed708c | 99:d98e315308cd |
|---|---|
| 5 $baseDir = dirname(__FILE__); | 5 $baseDir = dirname(__FILE__); |
| 6 $cache = ScriptIncludeCache::instance(__FILE__); | 6 $cache = ScriptIncludeCache::instance(__FILE__); |
| 7 $cache->includeOnce('Http.inc', $baseDir); | 7 $cache->includeOnce('Http.inc', $baseDir); |
| 8 $cache->includeOnce('Page.inc', $baseDir); | 8 $cache->includeOnce('Page.inc', $baseDir); |
| 9 $cache->includeOnce('common-functions.inc', $baseDir); | 9 $cache->includeOnce('common-functions.inc', $baseDir); |
| 10 $cache->includeOnce('CacheTimeCheck.inc', $baseDir); | |
| 10 /// @endcond | 11 /// @endcond |
| 12 | |
| 13 class SimpleCache extends Cache { | |
| 14 private $time; | |
| 15 | |
| 16 function __construct($time = 0) { | |
| 17 $this->time = $time; | |
| 18 } | |
| 19 function getNewest() { | |
| 20 return $this->time; | |
| 21 } | |
| 22 }; | |
| 11 | 23 |
| 12 function cmp_length_lex($a, $b) | 24 function cmp_length_lex($a, $b) |
| 13 { | 25 { |
| 14 if ($a == $b) { | 26 if ($a == $b) { |
| 15 return 0; | 27 return 0; |
| 39 function __construct($path) { | 51 function __construct($path) { |
| 40 $this->master = new DOMDocument(); | 52 $this->master = new DOMDocument(); |
| 41 $this->master->load($path); | 53 $this->master->load($path); |
| 42 | 54 |
| 43 $this->options = new Options($this->master); | 55 $this->options = new Options($this->master); |
| 56 $this->lastmod=0; | |
| 44 } | 57 } |
| 45 | 58 |
| 46 function cacheCheck() | 59 function cacheCheck() |
| 47 { | 60 { |
| 48 return false; | 61 if ($this->lastmod == 0) |
| 62 return Cacheable::UNDETERMINED; | |
| 63 else | |
| 64 return Cacheable::YES; | |
| 49 } | 65 } |
| 50 | 66 |
| 51 function mayValidate() | 67 function mayValidate() |
| 52 { | 68 { |
| 53 return false; | 69 return false; |
| 123 | 139 |
| 124 $n = StatusCodes::codeFromHeader($headers['']); | 140 $n = StatusCodes::codeFromHeader($headers['']); |
| 125 | 141 |
| 126 if ($n == StatusCodes::HTTP_OK) { | 142 if ($n == StatusCodes::HTTP_OK) { |
| 127 $lastmod = strtotime($lastmod); | 143 $lastmod = strtotime($lastmod); |
| 144 if ($lastmod > $this->lastmod) { | |
| 145 $this->lastmod = $lastmod; | |
| 146 } | |
| 128 $lastmod = date(DateTime::W3C, $lastmod); | 147 $lastmod = date(DateTime::W3C, $lastmod); |
| 129 | 148 |
| 130 $out .= "<url>\n"; | 149 $out .= "<url>\n"; |
| 131 $out .= "<loc>${location}</loc>\n"; | 150 $out .= "<loc>${location}</loc>\n"; |
| 132 $out .= "<lastmod>${lastmod}</lastmod>\n"; | 151 $out .= "<lastmod>${lastmod}</lastmod>\n"; |
| 135 } | 154 } |
| 136 | 155 |
| 137 $out .= '</urlset>'; | 156 $out .= '</urlset>'; |
| 138 | 157 |
| 139 $res = new PageContent($out); | 158 $res = new PageContent($out); |
| 159 $cache=new SimpleCache($this->lastmod); | |
| 160 $cache->setMaxAge(86400); | |
| 161 $this->setCache($cache); | |
| 140 $res->setHeader('Content-type', 'application/xml'); | 162 $res->setHeader('Content-type', 'application/xml'); |
| 141 return $res; | 163 return $res; |
| 142 } | 164 } |
| 143 } | 165 } |
| 144 ?> | 166 ?> |
