Mercurial > SimpleWebPresenter
changeset 16:a64e8f968e7e
Fast abort if cachehit.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 19 Sep 2012 14:31:02 +0200 |
| parents | f51be7b9711a |
| children | 75ab765300d1 |
| files | cache_check.inc index.php |
| diffstat | 2 files changed, 33 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/cache_check.inc Wed Sep 19 14:17:35 2012 +0200 +++ b/cache_check.inc Wed Sep 19 14:31:02 2012 +0200 @@ -15,4 +15,11 @@ } header("Last-Modified: $gmdate_mod"); } + +function cache_time($path) { + $mtime = filemtime($path); + if ($mtime > $newest) { + $newest = $mtime; + } +} ?> \ No newline at end of file
--- a/index.php Wed Sep 19 14:17:35 2012 +0200 +++ b/index.php Wed Sep 19 14:31:02 2012 +0200 @@ -145,11 +145,28 @@ } foreach ($files as $file) { - $script=$file->getAttribute("script"); + if ($file->getAttribute("script")) { + $cachable = false; + break; + } + else { + $src = $file->getAttribute("src"); + $fname = "${lang}/${src}"; + if (!file_exists($fname)) { + errorPage("Resource not found '${fname}'"); + } + cache_time($fname); + } +} + +if ($cachable) + cache_check($newest); + +foreach ($files as $file) { + $script = $file->getAttribute("script"); if ($script) { - $cachable = false; - $src=""; - $cwd=getcwd(); + $src = ""; + $cwd = getcwd(); $matches=array(); preg_match('/(.*\/)/', $script, $matches); @@ -162,15 +179,11 @@ chdir("${cwd}"); } else { - $src=$file->getAttribute("src"); - $fname = "${lang}/${src}"; - $mtime = filemtime($fname); - if ($mtime > $newest) { - $newest = $mtime; - } - $file_content=loadFile($fname); + $src = $file->getAttribute("src"); + $fname = "${lang}/${src}"; + $file_content = loadFile($fname); } - if(floatval($file_content)<0) { + if(floatval($file_content) < 0) { errorPage("Resource not found '${lang}/${src}'"); } @@ -194,8 +207,7 @@ } $out.= $file_content; } -if ($cachable) - cache_check($newest); + $out.='
