diff --git a/Classes/Generator/ConfigGenerator.php b/Classes/Generator/ConfigGenerator.php index 36c77844855..306d47d55ff 100644 --- a/Classes/Generator/ConfigGenerator.php +++ b/Classes/Generator/ConfigGenerator.php @@ -8,14 +8,19 @@ use SFC\Staticfilecache\Event\GeneratorCreate; use SFC\Staticfilecache\Event\GeneratorRemove; use SFC\Staticfilecache\Service\ConfigurationService; +use SFC\Staticfilecache\Service\DateTimeService; use TYPO3\CMS\Core\Utility\GeneralUtility; class ConfigGenerator extends AbstractGenerator { public function generate(GeneratorCreate $generatorCreateEvent): void { + $time = (new DateTimeService())->getCurrentTime(); $config = [ - 'generated' => date('r'), + 'generated' => date('r', $time), + 'generatedTimestamp' => $time, + 'invalidAt' => date('r', $time + $generatorCreateEvent->getLifetime()), + 'invalidAtTimestamp' => $time + $generatorCreateEvent->getLifetime(), 'headers' => GeneralUtility::makeInstance(ConfigurationService::class) ->getValidHeaders($generatorCreateEvent->getResponse()->getHeaders(), 'validFallbackHeaders'), ]; diff --git a/Classes/Middleware/FallbackMiddleware.php b/Classes/Middleware/FallbackMiddleware.php index a70144aab0b..221ab655142 100644 --- a/Classes/Middleware/FallbackMiddleware.php +++ b/Classes/Middleware/FallbackMiddleware.php @@ -54,13 +54,19 @@ protected function handleViaFallback(ServerRequestInterface $request): ResponseI throw new Exception('Could not use fallback, because: ' . implode(', ', $event->getExplanation()), 1236781); } - $uri = $request->getUri(); + $uri = $request->getUri()->withQuery(''); if (isset($_COOKIE[CookieService::FE_COOKIE_NAME]) && 'typo_user_logged_in' === $_COOKIE[CookieService::FE_COOKIE_NAME]) { throw new Exception('StaticFileCache Cookie is set', 12738912); } $possibleStaticFile = $this->identifierBuilder->getFilepath((string) $uri); + + $config = $this->getCacheConfiguration($possibleStaticFile); + + if (isset($config['invalidAtTimestamp']) && $config['invalidAtTimestamp'] < time()) { + throw new Exception('Cache entry is old', 16237867241); + } $headers = $this->getHeaders($event->getRequest(), $possibleStaticFile);