From 389d2aeb62ff8755691392953ae2044b7fad5ada Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 9 Nov 2013 22:01:54 +0100 Subject: cache file/thumbnail responses Signed-off-by: Florian Pritz --- application/controllers/file.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'application') diff --git a/application/controllers/file.php b/application/controllers/file.php index 8e2f35430..b0561a52c 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -380,17 +380,25 @@ class File extends MY_Controller { $etag = "$id-thumb"; handle_etag($etag); - $thumb = $this->mfile->makeThumb($id, 150, IMAGETYPE_JPEG); - - if ($thumb === false) { - show_error("Failed to generate thumbnail"); - } + $thumb_size = 150; $filedata = $this->mfile->get_filedata($id); if (!$filedata) { show_error("Failed to get file data"); } + $cache_key = $filedata['hash'].'_thumb_'.$thumb_size; + + $thumb = cache_function($cache_key, 100, function() use ($id, $thumb_size){ + $thumb = $this->mfile->makeThumb($id, $thumb_size, IMAGETYPE_JPEG); + + if ($thumb === false) { + show_error("Failed to generate thumbnail"); + } + + return $thumb; + }); + $this->output->set_header("Cache-Control:max-age=31536000, public"); $this->output->set_header("Expires: ".date("r", time() + 365 * 24 * 60 * 60)); $this->output->set_content_type("image/jpeg"); -- cgit v1.2.3-24-g4f1b