Skip to content

Commit f76853a

Browse files
committed
BUGFIX: Use HeaderEnabled instead of HeaderLifetime to determine cachability
That way caching is supported even if no lifetime is set and the cache is valid ad infinitum
1 parent 80f6699 commit f76853a

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

Classes/Aspects/ContentCacheAspect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ContentCacheAspect
2828
protected $cacheFrontend;
2929

3030
/**
31-
* @Flow\Before("method(Neos\Fusion\Core\Cache\ContentCache->(createUncachedSegment|replaceUncachedPlaceholders)())")
31+
* @Flow\Before("method(Neos\Fusion\Core\Cache\ContentCache->(createUncachedSegment)())")
3232
*/
3333
public function grabUncachedSegment(JoinPointInterface $joinPoint)
3434
{

Classes/Middleware/CacheHeaderMiddleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6969
->withHeader('CacheControl', 'public, max-age=' . $publicLifetime);
7070
}
7171

72+
$response = $response
73+
->withHeader(RequestCacheMiddleware::HEADER_ENABLED, "");
74+
7275
if ($tags) {
7376
$response = $response
7477
->withHeader(RequestCacheMiddleware::HEADER_TAGS, $tags);

Classes/Middleware/RequestCacheMiddleware.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7474

7575
$response = $next->handle($request->withHeader(self::HEADER_ENABLED, ''));
7676

77-
if ($response->hasHeader(self::HEADER_LIFTIME)) {
78-
$lifetime = (int)$response->getHeaderLine(self::HEADER_LIFTIME);
79-
$tags = $response->getHeader(self::HEADER_TAGS);
77+
if ($response->hasHeader(self::HEADER_ENABLED)) {
78+
$lifetime = $response->hasHeader(self::HEADER_LIFTIME) ? (int)$response->getHeaderLine(self::HEADER_LIFTIME) : null;
79+
$tags = $response->hasHeader(self::HEADER_TAGS) ? $response->getHeader(self::HEADER_TAGS) : [];
8080
$response = $response
81+
->withoutHeader(self::HEADER_ENABLED)
8182
->withoutHeader(self::HEADER_LIFTIME)
82-
->withoutHeader(self::HEADER_TAGS)
83-
->withHeader(self::HEADER_INFO, 'MISS: ' . $entryIdentifier);
84-
83+
->withoutHeader(self::HEADER_TAGS);
8584

8685
$this->cacheFrontend->set($entryIdentifier,[ 'timestamp' => time(), 'response' => str($response) ], $tags, $lifetime);
8786
$response->getBody()->rewind();
87+
return $response->withHeader(self::HEADER_INFO, 'MISS: ' . $entryIdentifier);
8888
}
8989

9090
return $response;

0 commit comments

Comments
 (0)