diff --git a/inc/config.php b/inc/config.php index 6df9a79f..0e2205cc 100644 --- a/inc/config.php +++ b/inc/config.php @@ -53,11 +53,8 @@ $config['memcached']['servers'] = Array( Array('localhost', 11211) ); - // Experimental: cache entire thread HTML (for mods, since we already cache it with static HTML anyway) - // Increases load times for mods but might take up a bit of memory - $config['memcached']['cache_threads'] = false; // Timeout for cached objects such as posts and HTML - $config['memcached']['timeout'] = 86400; // one day + $config['memcached']['timeout'] = 43200; // 12 hours // The name of the session cookie (PHP's $_SESSION) $config['cookies']['session']= 'imgboard'; diff --git a/inc/functions.php b/inc/functions.php index c6646c4d..d5d38235 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -588,12 +588,10 @@ } function index($page, $mod=false) { - global $board, $config; + global $board, $config, $memcached; $body = ''; $offset = round($page*$config['threads_per_page']-$config['threads_per_page']); - - $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT ?,?", $board['uri'])); $query->bindValue(1, $offset, PDO::PARAM_INT); @@ -603,7 +601,14 @@ if($query->rowcount() < 1 && $page > 1) return false; while($th = $query->fetch()) { $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $th['embed'], $mod ? '?/' : $config['root'], $mod); - + + if($config['memcached']['enabled']) { + if($built = $memcached->get("theadindex_{$th['id']}")) { + $body .= $built; + continue; + } + } + $posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); $posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT); @@ -630,7 +635,14 @@ } $thread->posts = array_reverse($thread->posts); - $body .= '