From 3520a10f0df5b3dd094d5f68d3ff5305b32d92aa Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 8 Oct 2011 17:46:48 +1100 Subject: [PATCH] additional cache --- inc/functions.php | 21 +++++++++++++++++++++ mod.php | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/inc/functions.php b/inc/functions.php index 56bb011e..d5295b16 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -207,17 +207,29 @@ } function openBoard($uri) { + global $config; + if($config['cache']['enabled'] && ($board = cache::get('board_' . $uri))) { + setupBoard($board); + return true; + } + $query = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1"); $query->bindValue(':uri', $uri); $query->execute() or error(db_error($query)); if($board = $query->fetch()) { + if($config['cache']['enabled']) + cache::set('board_' . $uri, $board); setupBoard($board); return true; } else return false; } function boardTitle($uri) { + if($config['cache']['enabled'] && ($board = cache::get('board_' . $uri))) { + return $board['title']; + } + $query = prepare("SELECT `title` FROM `boards` WHERE `uri` = :uri LIMIT 1"); $query->bindValue(':uri', $uri); $query->execute() or error(db_error($query)); @@ -337,8 +349,17 @@ } function listBoards() { + global $config; + + if($config['cache']['enabled'] && ($boards = cache::get('all_boards'))) + return $boards; + $query = query("SELECT * FROM `boards` ORDER BY `uri`") or error(db_error()); $boards = $query->fetchAll(); + + if($config['cache']['enabled']) + cache::set('all_boards', $boards); + return $boards; } diff --git a/mod.php b/mod.php index 8ab39e68..6d8450c5 100644 --- a/mod.php +++ b/mod.php @@ -1415,6 +1415,11 @@ $query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); + if($config['cache']['enabled']) { + cache::delete('board_' . $board['uri']); + cache::delete('all_boards'); + } + rebuildThemes('boards'); header('Location: ?/', true, $config['redirect_http']); @@ -1431,6 +1436,11 @@ $query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); + if($config['cache']['enabled']) { + cache::delete('board_' . $board['uri']); + cache::delete('all_boards'); + } + rebuildThemes('boards'); openBoard($board['uri']);