From 9b93df4e22e58c4dc9a9a95652ab3e81f0e48390 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 27 Dec 2011 18:08:49 +0000 Subject: [PATCH 1/2] make apache cache-control/expires settings only apply to static files; shimmie will take care of the web pages --- .htaccess | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.htaccess b/.htaccess index 6a0c5ef1..ba0fda88 100644 --- a/.htaccess +++ b/.htaccess @@ -30,9 +30,12 @@ DefaultType image/jpeg ExpiresActive On - ExpiresDefault "access plus 1 month" - ExpiresByType text/html "now" - ExpiresByType text/plain "now" + + Header set Cache-Control "public, max-age=2629743" + ExpiresDefault "access plus 1 month" + + #ExpiresByType text/html "now" + #ExpiresByType text/plain "now" From cfbeddde9f492a4a0c2c593afaac3462ee17394c Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 27 Dec 2011 19:23:37 +0000 Subject: [PATCH 2/2] HTTP level caching, so we can stick varnish in front of the web pages --- core/page.class.php | 19 +++++++++++++++++-- ext/user/main.php | 5 +++++ index.php | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index b2a8d662..d382caf2 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -183,7 +183,7 @@ class Page { * Display the page according to the mode and data given */ public function display() { - global $page; + global $page, $user; header("Content-type: ".$this->type); header("X-Powered-By: SCore-".SCORE_VERSION); @@ -196,7 +196,22 @@ class Page { switch($this->mode) { case "page": - header("Cache-control: no-cache"); + header("Vary: Cookie, Accept-Encoding"); + if(CACHE_HTTP) { + if($user->is_anonymous() && $_SERVER["REQUEST_METHOD"] == "GET") { + header("Cache-control: public, max-age=600"); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 600) . ' GMT'); + } + else { + #header("Cache-control: private, max-age=0"); + header("Cache-control: no-cache"); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 600) . ' GMT'); + } + } + else { + header("Cache-control: no-cache"); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 600) . ' GMT'); + } usort($this->blocks, "blockcmp"); $this->add_auto_html_headers(); $layout = new Layout(); diff --git a/ext/user/main.php b/ext/user/main.php index 07f14867..0b1073fa 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -79,6 +79,11 @@ class UserPage extends SimpleExtension { } else if($event->get_arg(0) == "logout") { set_prefixed_cookie("session", "", time()+60*60*24*$config->get_int('login_memory'), "/"); + if(CACHE_HTTP) { + # to keep as few versions of content as possible, + # make cookies all-or-nothing + set_prefixed_cookie("user", "", time()+60*60*24*$config->get_int('login_memory'), "/"); + } log_info("user", "Logged out"); $page->set_mode("redirect"); $page->set_redirect(make_link()); diff --git a/index.php b/index.php index 6a800999..48458b0c 100644 --- a/index.php +++ b/index.php @@ -62,6 +62,7 @@ define("COVERAGE", true); define("CONTEXT", false); define("CACHE_MEMCACHE", false); define("CACHE_DIR", false); +define("CACHE_HTTP", false); define("VERSION", 'trunk'); define("SCORE_VERSION", 's2hack/'.VERSION); define("COOKIE_PREFIX", 'shm');