Skip to content

Commit

Permalink
Fix #426 - avoid deliver old cache entries with fallback middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Dec 10, 2024
1 parent 8f3ed5b commit 18e2f98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Classes/Generator/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
Expand Down
8 changes: 7 additions & 1 deletion Classes/Middleware/FallbackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 18e2f98

Please sign in to comment.