From 320877f80bcd9150614f88c9bb919a31a7544082 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 9 Feb 2010 07:42:21 +0000 Subject: [PATCH] URI based hash, for nginx compatability --- core/util.inc.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 61425789..40adaa9c 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -849,8 +849,8 @@ function _get_user() { } -$_cache_hash = null; $_cache_memcache = false; +$_cache_key = null; $_cache_filename = null; function _cache_active() { @@ -871,30 +871,27 @@ function _cache_log($text) { } function _start_cache() { - global $_cache_hash, $_cache_memcache, $_cache_filename; + global $_cache_memcache, $_cache_key, $_cache_filename; if(_cache_active()) { - $_cache_hash = md5($_SERVER["QUERY_STRING"]); - if(CACHE_MEMCACHE) { $_cache_memcache = new Memcache; $_cache_memcache->pconnect('localhost', 11211); - $zdata = $_cache_memcache->get($_cache_hash); + $_cache_key = "uri:".$_SERVER["REQUEST_URI"]; + $data = $_cache_memcache->get($_cache_key); if(DEBUG) { $stat = $zdata ? "hit" : "miss"; - _cache_log(time() . " " . $_cache_hash . sprintf(" %-12s ", $stat) . $_SERVER["QUERY_STRING"] . "\n"); + _cache_log(time() . " " . sprintf(" %-4s ", $stat) . $_cache_key . "\n"); } - if($zdata) { + if($data) { header("Content-type: text/html"); - $data = @gzuncompress($zdata); - if($data) { - print $data; - exit; - } + print $data; + exit; } } if(CACHE_DIR) { + $_cache_hash = md5($_SERVER["QUERY_STRING"]); $ab = substr($_cache_hash, 0, 2); $cd = substr($_cache_hash, 2, 2); $_cache_filename = "data/$ab/$cd/$_cache_hash"; @@ -934,15 +931,16 @@ function _start_cache() { } function _end_cache() { - global $_cache_hash, $_cache_memcache, $_cache_filename; + global $_cache_memcache, $_cache_key, $_cache_filename; if(_cache_active()) { - $data = gzcompress(ob_get_contents(), 9); + $data = ob_get_contents(); if(CACHE_MEMCACHE) { - $_cache_memcache->set($_cache_hash, $data, 0, 600); + $_cache_memcache->set($_cache_key, $data, 0, 600); } if(CACHE_DIR) { - file_put_contents($_cache_filename, $data); + $zdata = gzcompress($data, 2); + file_put_contents($_cache_filename, $zdata); } } }