Mercurial > hg > batmud > maputils
changeset 1151:e0794ddb605e
Add output caching to main page and location page.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 21 Jul 2011 20:38:41 +0300 |
parents | 02fe48a608d7 |
children | a5542672a57e |
files | www/common.inc.php www/index.php www/loc.php |
diffstat | 3 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/www/common.inc.php Thu Jul 21 20:38:06 2011 +0300 +++ b/www/common.inc.php Thu Jul 21 20:38:41 2011 +0300 @@ -317,4 +317,25 @@ "</div>\n"; } + +function fetchPageFromCache() +{ + global $cacheFilename; + $cacheFilename = "cache/".md5($_SERVER["REQUEST_URI"]); + $cacheCreated = (file_exists($cacheFilename)) ? filemtime($cacheFilename) : 0; + if ((time() - $cacheCreated) < 3600) { + readfile($cacheFilename); + return TRUE; + } else + return FALSE; +} + +function storePageToCache() +{ + global $cacheFilename; + if (isset($cacheFilename)) { + file_put_contents($cacheFilename, ob_get_contents()); + ob_end_flush(); + } +} ?> \ No newline at end of file
--- a/www/index.php Thu Jul 21 20:38:06 2011 +0300 +++ b/www/index.php Thu Jul 21 20:38:41 2011 +0300 @@ -62,6 +62,10 @@ echo " </tr>\n"; } +if (fetchPageFromCache()) + exit; + +ob_start(); printPageHeader($pageTitle, "<link rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/maps/opensearch.xml\" title=\"PupuMaps\" />\n"); @@ -168,3 +172,6 @@ </body> </html> +<? +storePageToCache(); +?> \ No newline at end of file
--- a/www/loc.php Thu Jul 21 20:38:06 2011 +0300 +++ b/www/loc.php Thu Jul 21 20:38:41 2011 +0300 @@ -97,9 +97,14 @@ } } +if (empty($errorStr) && fetchPageFromCache()) { + exit; +} /* Start of the page */ +ob_start(); + printPageHeader($pageTitle." - Locations", "<script type=\"text/javascript\" src=\"tooltip.js\"></script>\n". "<meta name=\"robots\" content=\"nofollow\" />\n"); @@ -377,3 +382,7 @@ ?> </body> </html> +<? +if (empty($errorStr)) + storePageToCache(); +?> \ No newline at end of file