Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Cache-Control header setup to routes #443

Merged
merged 1 commit into from
Jan 16, 2022
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
15 changes: 0 additions & 15 deletions src/Controller/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public function __construct(App $app, SearcherInterface $searcher)

public function index(Request $request, Response $response): void
{
// The list changes whenever new profiles are recorded.
// Generally avoid caching, but allow re-use in browser's bfcache
// and by cache proxies for concurrent requests.
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=0');

$search = [];
$keys = ['date_start', 'date_end', 'server_name', 'url'];
foreach ($keys as $key) {
Expand Down Expand Up @@ -83,15 +77,6 @@ public function index(Request $request, Response $response): void

public function view(Request $request, Response $response): void
{
// Permalink views to a specific run are meant to be public and immutable.
// But limit the cache to only a short period of time (enough to allow
// handling of abuse or other stampedes). This way we don't have to
// deal with any kind of purging system for when profiles are deleted,
// or for after XHGui itself is upgraded and static assets may be
// incompatible etc.
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=60, must-revalidate');

$detailCount = $this->config('detail.count');
$result = $this->searcher->get($request->get('id'));

Expand Down
19 changes: 17 additions & 2 deletions src/ServiceProvider/RouteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,30 @@ private function registerRoutes(Container $di, App $app): void
$request = $app->request();
$response = $app->response();

// The list changes whenever new profiles are recorded.
// Generally avoid caching, but allow re-use in browser's bfcache
// and by cache proxies for concurrent requests.
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=0');

$controller->index($request, $response);
})->setName('home');

$app->get('/run/view', static function () use ($di, $app): void {
/** @var Controller\RunController $controller */
$controller = $di[Controller\RunController::class];
$request = $app->request();
$response = $app->response();

// Permalink views to a specific run are meant to be public and immutable.
// But limit the cache to only a short period of time (enough to allow
// handling of abuse or other stampedes). This way we don't have to
// deal with any kind of purging system for when profiles are deleted,
// or for after XHGui itself is upgraded and static assets may be
// incompatible etc.
// https://github.com/perftools/xhgui/issues/261
$response->headers->set('Cache-Control', 'public, max-age=60, must-revalidate');

/** @var Controller\RunController $controller */
$controller = $di[Controller\RunController::class];
$controller->view($request, $response);
})->setName('run.view');

Expand Down