Skip to content
Snippets Groups Projects

Issue #3350593: Use s-maxage instead of max-age

@@ -65,25 +65,26 @@ final class CacheControlOverrideSubscriber implements EventSubscriberInterface {
@@ -65,25 +65,26 @@ final class CacheControlOverrideSubscriber implements EventSubscriberInterface {
$maxAge = (int) $response->getCacheableMetadata()->getCacheMaxAge();
$maxAge = (int) $response->getCacheableMetadata()->getCacheMaxAge();
// We treat permanent cache max-age as default therefore we don't override
if ($maxAge == CacheBackendInterface::CACHE_PERMANENT) {
// the max-age.
// Permanent is -1 so we must replace it with the value from core configuration.
if ($maxAge !== CacheBackendInterface::CACHE_PERMANENT) {
$maxAge = $this->configFactory->get('system.performance')->get('cache.page.max_age');
// If max-age is not uncacheable (0), check if max-age should be changed.
}
if ($maxAge > 0) {
// Force minimum max-age if configured.
// If max-age is not uncacheable (0), check if max-age should be changed.
$minimum = $this->getMaxAgeMinimum();
if ($maxAge > 0) {
if ($minimum !== NULL) {
// Force minimum max-age if configured.
$maxAge = max($minimum, $maxAge);
$minimum = $this->getMaxAgeMinimum();
}
if ($minimum !== NULL) {
$maxAge = max($minimum, $maxAge);
// Force maximum max-age if configured.
}
$maximum = $this->getMaxAgeMaximum();
if ($maximum !== NULL && $maximum !== CacheBackendInterface::CACHE_PERMANENT) {
// Force maximum max-age if configured.
$maxAge = min($maximum, $maxAge);
$maximum = $this->getMaxAgeMaximum();
}
if ($maximum !== NULL && $maximum !== CacheBackendInterface::CACHE_PERMANENT) {
 
$maxAge = min($maximum, $maxAge);
}
}
$response->headers->set('Cache-Control', 'public, max-age=' . $maxAge);
}
}
 
$response->headers->set('Cache-Control', 'public, max-age=0, must-revalidate, s-maxage=' . $maxAge);
}
}
/**
/**
Loading