diff options
| author | Savetheinternet <savetheinternet@tinyboard.org> | 2011-05-19 21:50:19 +1000 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@tinyboard.org> | 2011-05-19 21:50:19 +1000 |
| commit | e60a6a1a582478d76893beec7408e7ea752c876c (patch) | |
| tree | 2e2ffd912f616eec0ff6f439567f271655c38626 /inc | |
| parent | fcab256146bd9ef25028cf0e484360df841c1f8e (diff) | |
cache built posts' HTML with memcached
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/config.php | 2 | ||||
| -rw-r--r-- | inc/display.php | 11 | ||||
| -rw-r--r-- | inc/functions.php | 2 |
3 files changed, 13 insertions, 2 deletions
diff --git a/inc/config.php b/inc/config.php index cceaabe2..6df9a79f 100644 --- a/inc/config.php +++ b/inc/config.php @@ -56,6 +56,8 @@ // 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 // The name of the session cookie (PHP's $_SESSION) $config['cookies']['session']= 'imgboard'; diff --git a/inc/display.php b/inc/display.php index 7ec95ef3..9c7843b9 100644 --- a/inc/display.php +++ b/inc/display.php @@ -260,7 +260,12 @@ } public function build($index=false) { - global $board, $config; + global $board, $config, $memcached; + + if(!$this->mod && $config['memcached']['enabled']) { + if($built = $memcached->get('post_' . ($index ? 'index_' : '') . $board['uri'] . '_' . $this->id)) + return $built; + } $built = '<div class="post reply" id="reply_' . $this->id . '">' . '<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>' . @@ -347,6 +352,10 @@ // Body $built .= '<p class="body">' . ($index ? truncate($this->body, $this->link()) : $this->body) . '</p></div><br class="clear"/>'; + if(!$this->mod && $config['memcached']['enabled']) { + $memcached->set('post_' . ($index ? 'index_' : '') . $board['uri'] . '_' . $this->id, $built, time() + $config['memcached']['timeout']); + } + return $built; } }; diff --git a/inc/functions.php b/inc/functions.php index ae23a5ef..b0d97dc4 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1258,7 +1258,7 @@ )); if($config['memcached']['cache_threads'] && $config['memcached']['enabled']) { - $memcached->set('thread_' . $board['uri'] . '_' . $id, $body, time() + 86400); + $memcached->set('thread_' . $board['uri'] . '_' . $id, $body, time() + $config['memcached']['timeout']); } if($return) |
