Skip to content

Commit 9191402

Browse files
committed
Cache single version json API for a day as these should never change
1 parent aa69ea4 commit 9191402

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Controller/PackageController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,13 +776,19 @@ public function viewPackageVersionAction(Request $req, int $versionId): JsonResp
776776
try {
777777
$html = $this->renderView(
778778
'package/version_details.html.twig',
779-
['version' => $repo->getFullVersion($versionId)]
779+
['version' => $version = $repo->getFullVersion($versionId)]
780780
);
781781
} catch (NoResultException $e) {
782782
return new JsonResponse(['status' => 'error', 'message' => 'The version could not be found, it may have been deleted in the meantime? Try reloading the page.'], 404);
783783
}
784784

785-
return new JsonResponse(['content' => $html]);
785+
$resp = new JsonResponse(['content' => $html]);
786+
if (!$version->isDevelopment()) {
787+
$resp->setSharedMaxAge(24 * 3600);
788+
$resp->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
789+
}
790+
791+
return $resp;
786792
}
787793

788794
#[Route(path: '/versions/{versionId}/delete', name: 'delete_version', requirements: ['name' => '[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?', 'versionId' => '[0-9]+'], methods: ['DELETE'])]

0 commit comments

Comments
 (0)