1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-02 19:17:21 +01:00

additional cache

This commit is contained in:
Savetheinternet 2011-10-08 17:46:48 +11:00
parent 9ba135ffcd
commit 3520a10f0d
2 changed files with 31 additions and 0 deletions

View File

@ -207,17 +207,29 @@
} }
function openBoard($uri) { 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 = prepare("SELECT * FROM `boards` WHERE `uri` = :uri LIMIT 1");
$query->bindValue(':uri', $uri); $query->bindValue(':uri', $uri);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($board = $query->fetch()) { if($board = $query->fetch()) {
if($config['cache']['enabled'])
cache::set('board_' . $uri, $board);
setupBoard($board); setupBoard($board);
return true; return true;
} else return false; } else return false;
} }
function boardTitle($uri) { 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 = prepare("SELECT `title` FROM `boards` WHERE `uri` = :uri LIMIT 1");
$query->bindValue(':uri', $uri); $query->bindValue(':uri', $uri);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
@ -337,8 +349,17 @@
} }
function listBoards() { 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()); $query = query("SELECT * FROM `boards` ORDER BY `uri`") or error(db_error());
$boards = $query->fetchAll(); $boards = $query->fetchAll();
if($config['cache']['enabled'])
cache::set('all_boards', $boards);
return $boards; return $boards;
} }

10
mod.php
View File

@ -1415,6 +1415,11 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['cache']['enabled']) {
cache::delete('board_' . $board['uri']);
cache::delete('all_boards');
}
rebuildThemes('boards'); rebuildThemes('boards');
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
@ -1431,6 +1436,11 @@
$query->bindValue(':id', $board['id'], PDO::PARAM_INT); $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['cache']['enabled']) {
cache::delete('board_' . $board['uri']);
cache::delete('all_boards');
}
rebuildThemes('boards'); rebuildThemes('boards');
openBoard($board['uri']); openBoard($board['uri']);