From 683cf79fe6fe6d3079998e8bfe6e3cf926918454 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 14 Oct 2010 23:52:30 +0000 Subject: [PATCH] BUGFIX Bypass static caching through static-main.php when GET or POST parameters are set (regression from 2.3 API, fixes #5519, thanks ktauber) (from r103961) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112327 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- static-main.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/static-main.php b/static-main.php index 65291e264..c0cfe2640 100644 --- a/static-main.php +++ b/static-main.php @@ -22,8 +22,15 @@ $cacheBaseDir = '../cache/'; // Should point to the same folder as FilesystemPub $hostmapLocation = '../subsites/host-map.php'; $homepageMapLocation = '../assets/_homepage-map.php'; -if ($cacheEnabled && empty($_COOKIE['bypassStaticCache'])) { - +if ( + $cacheEnabled + && empty($_COOKIE['bypassStaticCache']) + // No GET params other than cache relevant config is passed (e.g. "?stage=Stage"), + // which would mean that we have to bypass the cache + && count(array_diff(array_keys($_GET), array('url', 'cacheSubdir'))) == 0 + // Request is not POST (which would have to be handled dynamically) + && count($_POST) == 0 +) { // Define system paths (copied from Core.php) if(!defined('BASE_PATH')) { // Assuming that this file is sapphire/static-main.php we can then determine the base path @@ -75,6 +82,7 @@ if ($cacheEnabled && empty($_COOKIE['bypassStaticCache'])) { // Find file by extension (either *.html or *.php) $file = preg_replace('/[^a-zA-Z0-9\/\-_]/si', '-', $file); + if (file_exists($cacheBaseDir . $cacheDir . $file . '.html')) { header('X-SilverStripe-Cache: hit at '.@date('r')); echo file_get_contents($cacheBaseDir . $cacheDir . $file . '.html');