Skip to content

Commit a0b976f

Browse files
committed
bug symfony#35299 Avoid stale-if-error in FrameworkBundle's HttpCache if kernel.debug = true (mpdude)
This PR was merged into the 3.4 branch. Discussion ---------- Avoid `stale-if-error` in FrameworkBundle's HttpCache if kernel.debug = true | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#24248 (maybe?) | License | MIT | Doc PR | When working with the `HttpCache` in development, error messages may not become visible if a `public` response has been successfully generated for the same URL before. This is because the `HttpCache` from the `HttpKernel` component by default sets `stale_if_error` to 60 seconds. At least when using the `HttpCache` subclass from the `FrameworkBundle`, we know about the `kernel.debug` setting and its intention to support local development. In that case, we could set the *default* `stale-if-error` value to 0. Commits ------- 3a23ec8 Avoid stale-if-error if kernel.debug = true, because it hides errors
2 parents d1e31a4 + 3a23ec8 commit a0b976f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public function __construct(KernelInterface $kernel, $cacheDir = null)
3737
$this->kernel = $kernel;
3838
$this->cacheDir = $cacheDir;
3939

40-
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge(['debug' => $kernel->isDebug()], $this->getOptions()));
40+
$isDebug = $kernel->isDebug();
41+
$options = ['debug' => $isDebug];
42+
43+
if ($isDebug) {
44+
$options['stale_if_error'] = 0;
45+
}
46+
47+
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($options, $this->getOptions()));
4148
}
4249

4350
/**

0 commit comments

Comments
 (0)