From 6e774619c1feb4039ac21397bac9570715acb15c Mon Sep 17 00:00:00 2001 From: Phyks Date: Mon, 2 Sep 2013 00:23:37 +0200 Subject: [PATCH] Cache system ; use a different cache file per user... will see how to improve it --- TODO | 5 ++++- index.php | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index e245951..8ff3bfb 100755 --- a/TODO +++ b/TODO @@ -4,7 +4,10 @@ inc/Invoices.class.php : ======================== * Modify store() method to handle storage * Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2) -* Cache + +========== +* Don't cache the username +========== Manage paybacks : ================= diff --git a/index.php b/index.php index b7510a1..1397179 100644 --- a/index.php +++ b/index.php @@ -161,6 +161,10 @@ if(!empty($_POST['user_id']) || $user->isUnique()) { $user->save(); + + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); + header('location: index.php?do=edit_users'); exit(); } @@ -203,6 +207,9 @@ $user->setId($_GET['user_id']); $user->delete(); + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); + header('location: index.php?do=edit_users'); exit(); } @@ -211,6 +218,9 @@ case 'edit_notice': if(isset($_POST['notice'])) { setNotice($_POST['notice']); + + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); header('location: index.php'); exit(); @@ -252,6 +262,9 @@ } if(file_put_contents("data/config.php", $config)) { + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); + header('location: index.php'); exit(); } @@ -323,6 +336,10 @@ $invoice->setGuests($guests); $invoice->save(); + + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); + header('location: index.php'); exit(); } @@ -359,6 +376,9 @@ $invoice->setId($_GET['id']); $invoice->delete(); + // Clear the cache + array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php")); + header('location: index.php'); exit(); } @@ -366,7 +386,7 @@ default: // Display cached page in priority - if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = NULL)) { + if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = $current_user->getLogin())) { echo $cache; } else { @@ -380,7 +400,7 @@ $tpl->assign('invoices', secureDisplay($invoices_list)); // Cache the page (1 month to make it almost permanent and only regenerate it upon new invoice) - $tpl->cache('index', 108000, NULL); + $tpl->cache('index', 108000, $current_user->getLogin()); $tpl->draw('index'); break;