summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-11-09 22:01:54 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-11-09 22:01:54 +0100
commit389d2aeb62ff8755691392953ae2044b7fad5ada (patch)
tree687aacc98fa8ea97be125e37014595c485d37234 /application
parent853303f104c576ddaaa2e645b7f4334bd2157053 (diff)
cache file/thumbnail responses
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/file.php18
1 files changed, 13 insertions, 5 deletions
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");