diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-21 12:51:22 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-11-03 14:00:33 +0100 |
commit | 9e6b26dcd05362599bade82d7b326336a5cc7c0b (patch) | |
tree | 15ece4612b963dc3a9705cec4491253da329b69e /core/Controller/PreviewController.php | |
parent | 55af6b45f72e0717d7b6f07b69bc0f12f4fb4cd9 (diff) | |
download | nextcloud-server-9e6b26dcd05362599bade82d7b326336a5cc7c0b.tar.gz nextcloud-server-9e6b26dcd05362599bade82d7b326336a5cc7c0b.zip |
Add cache 1 day cache to preview endpoint
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/Controller/PreviewController.php')
-rw-r--r-- | core/Controller/PreviewController.php | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 3a245374e96..4b9ba8b60d4 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -24,6 +24,7 @@ namespace OC\Core\Controller; use OCP\AppFramework\Controller; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\File; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -44,6 +45,9 @@ class PreviewController extends Controller { /** @var IPreview */ private $preview; + /** @var ITimeFactory */ + private $timeFactory; + /** * PreviewController constructor. * @@ -57,13 +61,15 @@ class PreviewController extends Controller { IRequest $request, IPreview $preview, IRootFolder $root, - $userId + $userId, + ITimeFactory $timeFactory ) { parent::__construct($appName, $request); $this->preview = $preview; $this->root = $root; $this->userId = $userId; + $this->timeFactory = $timeFactory; } /** @@ -105,7 +111,19 @@ class PreviewController extends Controller { try { $f = $this->preview->getPreview($file, $x, $y, !$a, $mode); - return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); + + // Let cache this! + $response->addHeader('Pragma', 'public'); + + // Cache previews for 24H + $response->cacheFor(3600 * 24); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('P1D')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + + return $response; } catch (NotFoundException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } |