diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-04 15:25:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-04 15:25:17 +0200 |
commit | 2794d62f6088dd69a9e056825f31e326d599ea31 (patch) | |
tree | 653181fed8a4054e4557996d4bc9dc8cdaa2a9ab /lib | |
parent | 15bd898ffca7e4e72f675a1b9df7d6c58b4334c6 (diff) | |
parent | e5cc8be9d5f8899417aa0716b8b29c596417af61 (diff) | |
download | nextcloud-server-2794d62f6088dd69a9e056825f31e326d599ea31.tar.gz nextcloud-server-2794d62f6088dd69a9e056825f31e326d599ea31.zip |
Merge pull request #9641 from nextcloud/techdep/noid/caching_explicit_in_response
Move caching logic to response
Diffstat (limited to 'lib')
-rw-r--r-- | lib/public/AppFramework/Http/Response.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 512b312dae1..a6f5afd3c18 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -35,6 +35,7 @@ namespace OCP\AppFramework\Http; use OCP\AppFramework\Http; +use OCP\AppFramework\Utility\ITimeFactory; /** * Base class for responses. Also used to just send headers. @@ -95,12 +96,23 @@ class Response { * @return $this * @since 6.0.0 - return value was added in 7.0.0 */ - public function cacheFor($cacheSeconds) { - + public function cacheFor(int $cacheSeconds) { if($cacheSeconds > 0) { $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); + + // Old scool prama caching + $this->addHeader('Pragma', 'public'); + + // Set expires header + $expires = new \DateTime(); + /** @var ITimeFactory $time */ + $time = \OC::$server->query(ITimeFactory::class); + $expires->setTimestamp($time->getTime()); + $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); + $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); } else { $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); + unset($this->headers['Expires'], $this->headers['Pragma']); } return $this; |