From 3833ab7e3588b4f5c05f440713f5cdf30b9029ae Mon Sep 17 00:00:00 2001 From: root Date: Sun, 5 Oct 2014 21:15:08 +0200 Subject: Improved caching methods. --- action.php | 30 +++++++++++++++++------------- functions.php | 19 +++++++++++++++---- index.php | 2 +- static/header.php | 22 +++++++++++++++++----- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/action.php b/action.php index 86129ae..1e70b21 100644 --- a/action.php +++ b/action.php @@ -259,23 +259,27 @@ JG Adlershof"; $suffix = ".csv"; } lredirect("download;type=".$type); - $res = $db->doQuery("SELECT * FROM " . DBPREFIX . "member;"); - $content .= "\n"; - $count = 1; - while ($row = $res->fetch_array() ){ + if ( $c->exists(CACHEPREFIX . "adressliste".$suffix) ){ + $content = $c->getValue(CACHEPREFIX . "adressliste".$suffix); + } else { + $res = $db->doQuery("SELECT * FROM " . DBPREFIX . "member;"); + $content .= "\n"; + $count = 1; + while ($row = $res->fetch_array() ){ - if ( $type == "plain" ){ - $content .= $count . " | " . $row["name"] . " | " . $row["adresse"] . " | " . $row["telefonnummer"] . " | " . $row["handynummer"] . " | " . $row["email"] . " | " . $row["geburtstag"] . "\n"; - } else { - $content .= $count; - for ( $i=1;$i<7;$i++){ - $content .= ';' . $row[$i]; + if ( $type == "plain" ){ + $content .= $count . " | " . $row["name"] . " | " . $row["adresse"] . " | " . $row["telefonnummer"] . " | " . $row["handynummer"] . " | " . $row["email"] . " | " . $row["geburtstag"] . "\n"; + } else { + $content .= $count; + for ( $i=1;$i<7;$i++){ + $content .= ';' . $row[$i]; + } + $content .= "\n"; } - $content .= "\n"; + $count++; } - $count++; + $c->setKey(CACHEPREFIX . "adressliste".$suffix, $content); } - ob_clean(); header("Content-Type: text/".$type."; Charset=UTF-8"); header("Content-Disposition: attachment; filename=\"JG Adressliste ".date("j.n.Y", time()).$suffix."\""); diff --git a/functions.php b/functions.php index 62d5299..9f5ff49 100644 --- a/functions.php +++ b/functions.php @@ -161,6 +161,15 @@ function print_list($option = false){
+exists(CACHEPREFIX . "adressliste.html")){ + echo $c->getValue(CACHEPREFIX . "adressliste.html"); + header("X-Cache-Table: Hit"); + return; + } + ob_start(); ?>
@@ -188,10 +197,10 @@ function print_list($option = false){ ".htmlentities($row['adresse'])." ".htmlentities($row['telefonnummer'])." ".htmlentities($row['handynummer'])." - ".htmlentities($row['email'])." + ".htmlentities($row['email'])." ".htmlentities($row['geburtstag'])." - + "; $count++; } @@ -204,8 +213,10 @@ function print_list($option = false){
- setKey(CACHEPREFIX . "adressliste.html", $table); + ob_end_flush(); } function print_update_list($id){ @@ -617,7 +628,7 @@ function print_download(){ lredirect("download;type=".$type); header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Refresh: 2; ".DOMAIN."/?page=action&task=download&type=".$type); + header("Refresh: 0; ".DOMAIN."/?page=action&task=download&type=".$type); ?>

Download

Der Download der Adressliste (vom Typ 'text/') sollte automatisch starten.

diff --git a/index.php b/index.php index 52bf162..af2a619 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,7 @@ if ( ! isset($cache) ) $c = new cache(REDIS_CONNECT, REDIS_DB); if ( isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]){ - $a = "1_"; + $a = $_SESSION["userid"]."_"; } else { $a = "0_"; } diff --git a/static/header.php b/static/header.php index ff51e71..f6ecfd9 100644 --- a/static/header.php +++ b/static/header.php @@ -15,8 +15,8 @@
  • @@ -31,20 +31,32 @@ Fancy Mode