diff options
author | Julius Haertl <jus@bitgrid.net> | 2016-10-14 15:57:58 +0300 |
---|---|---|
committer | Julius Haertl <jus@bitgrid.net> | 2016-11-18 12:23:24 +0300 |
commit | 2e8dd218157123cdb7f1741980e12dc22b95f320 (patch) | |
tree | 08cc47865cc2b20bc61f07dc2a35e084d0423eb3 /apps/theming/lib/Controller | |
parent | 492d0b9f9bd72591183ff8bf4e8d5f9b4aecba35 (diff) |
Improve caching
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib/Controller')
-rw-r--r-- | apps/theming/lib/Controller/IconController.php | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php index eb65ae54f1a..887dba8a68a 100644 --- a/apps/theming/lib/Controller/IconController.php +++ b/apps/theming/lib/Controller/IconController.php @@ -96,7 +96,10 @@ class IconController extends Controller { } $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); $response->cacheFor(86400); - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); $response->addHeader('Pragma', 'cache'); return $response; } @@ -111,19 +114,24 @@ class IconController extends Controller { * @return FileDisplayResponse|DataDisplayResponse */ public function getFavicon($app = "core") { - $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); - if($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { - $icon = $this->iconBuilder->getFavicon($app); - $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); - } if ($this->themingDefaults->shouldReplaceIcons()) { + $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app); + if($iconFile === null) { + $icon = $this->iconBuilder->getFavicon($app); + $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon); + } $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']); + $response->cacheFor(86400); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $response->addHeader('Pragma', 'cache'); } else { $response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND); + $response->cacheFor(0); + $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); } - $response->cacheFor(86400); - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); - $response->addHeader('Pragma', 'cache'); return $response; } @@ -137,19 +145,24 @@ class IconController extends Controller { * @return FileDisplayResponse|DataDisplayResponse */ public function getTouchIcon($app = "core") { - $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); - if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) { - $icon = $this->iconBuilder->getTouchIcon($app); - $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); - } if ($this->themingDefaults->shouldReplaceIcons()) { + $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app); + if ($iconFile === null) { + $icon = $this->iconBuilder->getTouchIcon($app); + $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon); + } $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']); + $response->cacheFor(86400); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $response->addHeader('Pragma', 'cache'); } else { $response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND); + $response->cacheFor(0); + $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); } - $response->cacheFor(86400); - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); - $response->addHeader('Pragma', 'cache'); return $response; } }
\ No newline at end of file |