Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
Header set Cache-Control "max-age=15778463"
</FilesMatch>

<FilesMatch "\.(css|js|svg|gif|png|jpg|ico|wasm|tflite)(\?v=.*)?$">
Header set Cache-Control "max-age=15778463, immutable"
</FilesMatch>

# Let browsers cache WOFF files for a week
<FilesMatch "\.woff2?$">
Header set Cache-Control "max-age=604800"
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/lib/Controller/IconController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getThemedIcon(string $app, string $image): Response {
$iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
}
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
$response->cacheFor(86400);
$response->cacheFor(86400, false, true);
return $response;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/theming/tests/Controller/IconControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testGetThemedIcon() {
->with('icon-core-filetypes_folder.svg')
->willReturn($file);
$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
$expected->cacheFor(86400);
$expected->cacheFor(86400, false, true);
$this->assertEquals($expected, $this->iconController->getThemedIcon('core', 'filetypes/folder.svg'));
}

Expand Down
6 changes: 4 additions & 2 deletions core/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ private function fetchPreview(

try {
$f = $this->preview->getPreview($node, $x, $y, !$a, $mode);
$response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
$response->cacheFor(3600 * 24);
$response = new FileDisplayResponse($f, Http::STATUS_OK, [
'Content-Type' => $f->getMimeType(),
]);
$response->cacheFor(3600 * 24, false, true);
return $response;
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
Expand Down
4 changes: 2 additions & 2 deletions lib/public/AppFramework/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public function __construct() {
* @return $this
* @since 6.0.0 - return value was added in 7.0.0
*/
public function cacheFor(int $cacheSeconds, bool $public = false) {
public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutable = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be added to #29914 as it's changing public API (apps might extend Response to implement custom responses)? And backporting yields a new minor for the old stables?

Copy link
Member

@PhrozenByte PhrozenByte Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping this due to the imminent release of the first NC24 beta and patch releases for old stables.

Breaking 3rd-party apps in patch releases is bad 😉

@CarlSchwan @PVince81 @ChristophWurst @solracsf @Pytal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of an app that did extend Response to modify the cacheFor method?

Copy link
Member

@PhrozenByte PhrozenByte Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/nextcloud/cms_pico/blob/00c2c4c3a3058b8138ac540b3bb55a30253df3dd/lib/Http/PicoAssetResponse.php#L99-L126

Just to get this straight: I don't really have any issue with this change, it's fine, there must be a way to introduce features like this. However, it needs documentation and it must yield a new minor for the old stables, as app devs don't expect such things to change in patch releases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For others to follow: Also see nextcloud/cms_pico#195 for the ongoing discussion.

if ($cacheSeconds > 0) {
$pragma = $public ? 'public' : 'private';
$this->addHeader('Cache-Control', $pragma . ', max-age=' . $cacheSeconds . ', must-revalidate');
$this->addHeader('Cache-Control', sprintf('%s, max-age=%s, %s', $pragma, $cacheSeconds, ($immutable ? 'immutable' : 'must-revalidate')));
$this->addHeader('Pragma', $pragma);

// Set expires header
Expand Down