diff --git a/core/core.services.yml b/core/core.services.yml index 2c7e896..0487938 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -82,10 +82,10 @@ services: page_cache_policy.deny_open_session: class: Drupal\Core\PageCache\PolicyRule\DenyOpenSession page_cache_policy.use_internal_config: - class: Drupal\Core\PageCache\PolicyRule\InternalCacheConfig + class: Drupal\Core\PageCache\PolicyRule\RequireInternalCacheConfig arguments: ['@config.factory'] page_cache_policy.cache_max_age_config: - class: Drupal\Core\PageCache\PolicyRule\MaxAgeConfig + class: Drupal\Core\PageCache\PolicyRule\RequireMaxAgeConfig arguments: ['@config.factory'] page_cache_selector.internal_storage: class: Drupal\Core\PageCache\DelegatePageCache\PolicyBoundStorageSelector diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 5e99544..b2d3264 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -7,7 +7,8 @@ namespace Drupal\Core\EventSubscriber; -use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageManager; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -21,17 +22,17 @@ class FinishResponseSubscriber implements EventSubscriberInterface { /** * The LanguageManager object for retrieving the correct language code. * - * @var \Drupal\Core\Language\LanguageManagerInterface + * @var LanguageManager */ protected $languageManager; /** * Constructs a FinishResponseSubscriber object. * - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The LanguageManager object for retrieving the correct language code. + * @param LanguageManager $language_manager + * The LanguageManager object for retrieving the correct language code. */ - public function __construct(LanguageManagerInterface $language_manager) { + public function __construct(LanguageManager $language_manager) { $this->languageManager = $language_manager; } diff --git a/core/lib/Drupal/Core/PageCache/CacheControl/NoCache.php b/core/lib/Drupal/Core/PageCache/CacheControl/NoCache.php index a55949a..bc34e55 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControl/NoCache.php +++ b/core/lib/Drupal/Core/PageCache/CacheControl/NoCache.php @@ -15,10 +15,12 @@ * Defines a cache control generator which never allows caching. */ class NoCache extends CacheControlBase { + /** * {@inheritdoc} */ public function setCacheable(Response $response, Request $request) { $this->setNotCacheable($response, $request); } + } diff --git a/core/lib/Drupal/Core/PageCache/CacheControl/PrivateBrowser.php b/core/lib/Drupal/Core/PageCache/CacheControl/PrivateBrowser.php index ee13130..f45cc47 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControl/PrivateBrowser.php +++ b/core/lib/Drupal/Core/PageCache/CacheControl/PrivateBrowser.php @@ -15,6 +15,7 @@ * Cache control implementation for private browser cache. */ class PrivateBrowser extends CacheControlBase { + /** * Number of seconds the response should be kept by the browser cache. * @@ -50,4 +51,5 @@ public function setCacheable(Response $response, Request $request) { $response->headers->set('Cache-Control', 'private'); $response->setMaxAge($this->ttl); } + } diff --git a/core/lib/Drupal/Core/PageCache/CacheControl/PublicExternal.php b/core/lib/Drupal/Core/PageCache/CacheControl/PublicExternal.php index 732434c..b3ca376 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControl/PublicExternal.php +++ b/core/lib/Drupal/Core/PageCache/CacheControl/PublicExternal.php @@ -15,6 +15,7 @@ * Cache-Control header generator for responses allowed to be cached by proxies. */ class PublicExternal extends CacheControlBase { + /** * The number of seconds a cache may keep and deliver a response. * @@ -23,7 +24,7 @@ class PublicExternal extends CacheControlBase { protected $config; /** - * Whether or not "Vary: Cookie" should be added to the response. + * Whether or not a "Vary: Cookie" header should be added to the response. * * @var bool */ @@ -33,9 +34,10 @@ class PublicExternal extends CacheControlBase { * Construct Cache-Control header generator publicly cacheable responses. * * @param int $max_age - * The number of seconds a cache may keep and deliver a response. + * The number of seconds a cache may keep and deliver a response. Do not + * specify a value greater than one year (31536000 seconds). * @param bool $omit_vary_cookie - * Whether or not "Vary: Cookie" should be added to the response. + * Whether or not a "Vary: Cookie" header should be added to the response. */ public function __construct($max_age, $omit_vary_cookie) { $this->maxAge = (int) $max_age; @@ -60,7 +62,10 @@ public function __construct($max_age, $omit_vary_cookie) { * A request object. */ public function setCacheable(Response $response, Request $request) { - // Disable caching in ancient browsers and for HTTP/1.0 proxies and clients. + // HTTP/1.0 proxies do not support the Vary header, so prevent any caching + // by sending an Expires date in the past. HTTP/1.1 clients ignore the + // Expires header if a Cache-Control: max-age= directive is specified (see + // RFC 2616, section 14.9.3). if (!$response->headers->has('Expires')) { $this->setExpiresNoCache($response); } @@ -79,13 +84,9 @@ public function setCacheable(Response $response, Request $request) { $max_age = !$request->cookies->has(session_name()) || $vary_customized ? $this->maxAge : 0; $response->setMaxAge($max_age); - // Entity tag should change if the output changes. - if ($response->headers->has('Last-Modified')) { - $created = $response->getLastModified()->getTimestamp(); - } - else { - $created = REQUEST_TIME; - } + // ETag should change if the output changes. + $last_modified = $response->getLastModified(); + $created = $last_modified ? $last_modified->getTimestamp() : REQUEST_TIME; $response->setEtag($created); // Allow HTTP proxies to cache pages for anonymous users without a session @@ -133,4 +134,5 @@ protected function revalidateResponse(Response $response, Request $request, $cre } } } + } diff --git a/core/lib/Drupal/Core/PageCache/CacheControlBase.php b/core/lib/Drupal/Core/PageCache/CacheControlBase.php index cf5de23..a616490 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControlBase.php +++ b/core/lib/Drupal/Core/PageCache/CacheControlBase.php @@ -11,9 +11,10 @@ use Symfony\Component\HttpFoundation\Response; /** - * Defines an interface for Cache-Control header generators. + * A base class for Cache-Control header generators. */ abstract class CacheControlBase implements CacheControlInterface { + /** * {@inheritdoc} */ @@ -23,7 +24,7 @@ public function setNotCacheable(Response $response, Request $request) { // There is no point in sending along headers necessary for cache // revalidation, if caching by proxies and browsers is denied in the first - // place. Therefore remove Etag and Last-Modified in that case. + // place. Therefore remove Etag, Last-Modified and Vary in that case. $response->setEtag(NULL); $response->setLastModified(NULL); $response->setVary(NULL); @@ -39,12 +40,13 @@ protected function setCacheControlNoCache(Response $response) { /** * Disable caching in ancient browsers and for HTTP/1.0 proxies and clients. * - * HTTP/1.0 proxies does not support the Vary header, so prevent any caching - * by sending an Expires date in the past. HTTP/1.1 clients ignores the - * Expires header if a Cache-Control: max-age= directive is specified (see - * RFC 2616, section 14.9.3). + * HTTP/1.0 proxies do not support the Vary header, so prevent any caching by + * sending an Expires date in the past. HTTP/1.1 clients ignore the Expires + * header if a Cache-Control: max-age= directive is specified (see RFC 2616, + * section 14.9.3). */ protected function setExpiresNoCache(Response $response) { $response->setExpires(\DateTime::createFromFormat('j-M-Y H:i:s T', '19-Nov-1978 05:00:00 GMT')); } + } diff --git a/core/lib/Drupal/Core/PageCache/CacheControlDefaultFactory.php b/core/lib/Drupal/Core/PageCache/CacheControlDefaultFactory.php index 8b222e8..c623ce9 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControlDefaultFactory.php +++ b/core/lib/Drupal/Core/PageCache/CacheControlDefaultFactory.php @@ -12,8 +12,15 @@ /** * A cache control factory configured through config and settings. + * + * This factory constructs a \Drupal\Core\PageCache\CacheControl\PublicExternal + * instance. The following config-entry and setting is passed as arguments to + * the constructor: + * - max_age: Read from system.performance cache.page.max_age config value. + * - omit_vary_cookie: Read from the omit_vary_cookie setting. */ class CacheControlDefaultFactory { + /** * Config object for system performance configuration. * @@ -49,4 +56,5 @@ public function getPublicExternal() { $omit_vary_cookie = $this->settings->get('omit_vary_cookie'); return new CacheControl\PublicExternal($max_age, $omit_vary_cookie); } + } diff --git a/core/lib/Drupal/Core/PageCache/CacheControlInterface.php b/core/lib/Drupal/Core/PageCache/CacheControlInterface.php index 352692f..d520466 100644 --- a/core/lib/Drupal/Core/PageCache/CacheControlInterface.php +++ b/core/lib/Drupal/Core/PageCache/CacheControlInterface.php @@ -14,8 +14,9 @@ * Defines an interface for Cache-Control header generators. */ interface CacheControlInterface { + /** - * Add Cache-Control and Expire header to a cacheable response. + * Add Cache-Control and Expires header to a cacheable response. * * @param \Symfony\Component\HttpFoundation\Response $response * A response object. @@ -25,7 +26,7 @@ public function setCacheable(Response $response, Request $request); /** - * Add Cache-Control and Expire header for a response which is not cacheable. + * Add Cache-Control and Expires header for a response which is not cacheable. * * @param \Symfony\Component\HttpFoundation\Response $response * A response object. @@ -33,4 +34,5 @@ public function setCacheable(Response $response, Request $request); * A request object. */ public function setNotCacheable(Response $response, Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/CompoundPolicy.php b/core/lib/Drupal/Core/PageCache/CompoundPolicy.php index eb76e61..c4780f6 100644 --- a/core/lib/Drupal/Core/PageCache/CompoundPolicy.php +++ b/core/lib/Drupal/Core/PageCache/CompoundPolicy.php @@ -10,25 +10,26 @@ use Symfony\Component\HttpFoundation\Request; /** - * A policy implementation which can contain any number of rules. + * A page cache policy implementation which can contain any number of rules. */ class CompoundPolicy implements PolicyRuleInterface { + /** - * A list of all policy rules which will be applied to the request. + * A set of all policy rules which will be applied to the request. * * @var \Drupal\Core\PageCache\PolicyRuleInterface[] */ protected $rules = array(); /** - * A list of policy rules which are required to pass. + * A set of policy rules which are required to pass. * * @var \Drupal\Core\PageCache\PolicyRuleInterface[] */ protected $mandatoryRules = array(); /** - * A list of policy rule observers notified when results are available. + * A set of policy rule observers notified when results are available. * * @var \Drupal\Core\PageCache\CompoundPolicyObserverInterface[] */ @@ -90,4 +91,5 @@ protected function checkResult(array $result, array $rules) { $rules_result = array_intersect_key($result, $rules); return $rules_result == array_filter($rules_result); } + } diff --git a/core/lib/Drupal/Core/PageCache/CompoundPolicyObserverInterface.php b/core/lib/Drupal/Core/PageCache/CompoundPolicyObserverInterface.php index 3cb3b30..237c63f 100644 --- a/core/lib/Drupal/Core/PageCache/CompoundPolicyObserverInterface.php +++ b/core/lib/Drupal/Core/PageCache/CompoundPolicyObserverInterface.php @@ -8,11 +8,12 @@ namespace Drupal\Core\PageCache; /** - * Defines the interface for policy rule observers. + * Defines the interface for compound policy observers. */ interface CompoundPolicyObserverInterface { + /** - * Verify results produced by applying a set of policy rules. + * React to the result produced by applying a set of policy rules. * * @param \Drupal\Core\PageCache\PolicyRuleInterface[] $rules * A list of policy rules applied. @@ -20,4 +21,5 @@ * TRUE if all of the rules applied successfully. */ public function onCompoundPolicyResult(array $rules, $result); + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache.php index 00fc757..aec5b57 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache.php @@ -14,6 +14,7 @@ * Page cache implementation relying on selectors for storage / cache-control. */ class DelegatePageCache extends PageCacheBase { + /** * A list of storage selectors. * @@ -78,4 +79,5 @@ protected function selectCacheControl(Request $request) { } } } + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/CacheControlSelectorInterface.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/CacheControlSelectorInterface.php index ab7033d..60bf424 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/CacheControlSelectorInterface.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/CacheControlSelectorInterface.php @@ -10,9 +10,10 @@ use Symfony\Component\HttpFoundation\Request; /** - * Defines the interface for storage selector implementations. + * Defines the interface for cache control selector implementations. */ interface CacheControlSelectorInterface { + /** * Return a cache control object suitable for the given request. * @@ -20,7 +21,8 @@ * A request object. * * @return \Drupal\Core\PageCache\CacheControlInterface|NULL - * An appropriate storage or NULL if none is available. + * An appropriate cache control or NULL if none is available. */ public function selectCacheControl(Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundCacheControlSelector.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundCacheControlSelector.php index 492ac7e..c54f546 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundCacheControlSelector.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundCacheControlSelector.php @@ -14,6 +14,7 @@ * Defines the interface for cache control selector implementations. */ class PolicyBoundCacheControlSelector extends PolicyBoundSelectorBase implements CacheControlSelectorInterface { + /** * The cache control object selected when policies evaluate to TRUE. * @@ -39,4 +40,5 @@ public function selectCacheControl(Request $request) { return $this->cacheControl; } } + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundSelectorBase.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundSelectorBase.php index b6b6882..1669d4a 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundSelectorBase.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundSelectorBase.php @@ -15,6 +15,7 @@ * A base class implementing common methods for policy bound selector classes. */ class PolicyBoundSelectorBase implements CompoundPolicyObserverInterface { + /** * Flag indicating whether all policy rules applied successfully. * @@ -35,4 +36,5 @@ public function add(CompoundPolicy $policy, PolicyRuleInterface $rule) { public function onCompoundPolicyResult(array $rules, $result) { $this->policyResult = $result; } + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundStorageSelector.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundStorageSelector.php index efe888f..c68e82c 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundStorageSelector.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/PolicyBoundStorageSelector.php @@ -14,6 +14,7 @@ * Defines the interface for storage selector implementations. */ class PolicyBoundStorageSelector extends PolicyBoundSelectorBase implements StorageSelectorInterface { + /** * The storage object selected when policies evaluate to TRUE. * @@ -39,4 +40,5 @@ public function selectStorage(Request $request) { return $this->storage; } } + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/RegisterSelectorsPass.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/RegisterSelectorsPass.php index 7fe3331..c4e5acd 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/RegisterSelectorsPass.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/RegisterSelectorsPass.php @@ -51,4 +51,5 @@ public function process(ContainerBuilder $container) { } } } + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCache/StorageSelectorInterface.php b/core/lib/Drupal/Core/PageCache/DelegatePageCache/StorageSelectorInterface.php index cdbbbc3..000d9ab 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCache/StorageSelectorInterface.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCache/StorageSelectorInterface.php @@ -13,6 +13,7 @@ * Defines the interface for storage selector implementations. */ interface StorageSelectorInterface { + /** * Return a storage object suitable for the given request. * @@ -23,4 +24,5 @@ * An appropriate storage or NULL if none is available. */ public function selectStorage(Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/DelegatePageCacheFactory.php b/core/lib/Drupal/Core/PageCache/DelegatePageCacheFactory.php index 8222194..0bd70b2 100644 --- a/core/lib/Drupal/Core/PageCache/DelegatePageCacheFactory.php +++ b/core/lib/Drupal/Core/PageCache/DelegatePageCacheFactory.php @@ -14,6 +14,7 @@ * A page cache factory operating before the kernel exists. */ class DelegatePageCacheFactory extends PageCacheFactoryBase { + /** * The global policy to be used in order to test whether caching is allowed. * @@ -73,4 +74,5 @@ public function addStorageSelector(DelegatePageCache\StorageSelectorInterface $s public function addCacheControlSelector(DelegatePageCache\CacheControlSelectorInterface $cache_control_selector) { $this->cacheControlSelectors[] = $cache_control_selector; } + } diff --git a/core/lib/Drupal/Core/PageCache/FastPageCacheDatabaseFactory.php b/core/lib/Drupal/Core/PageCache/FastPageCacheDatabaseFactory.php index d0ddd68..c586a07 100644 --- a/core/lib/Drupal/Core/PageCache/FastPageCacheDatabaseFactory.php +++ b/core/lib/Drupal/Core/PageCache/FastPageCacheDatabaseFactory.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\PageCache\Storage\InternalCachePreKernelFactory. + * Contains \Drupal\Core\PageCache\FastPageCacheDatabaseFactory. */ namespace Drupal\Core\PageCache; @@ -17,6 +17,7 @@ * A page cache factory operating before the kernel exists. */ class FastPageCacheDatabaseFactory extends FastPageCacheFactoryBase { + /** * {@inheritdoc} */ @@ -29,4 +30,5 @@ public function getStorage(Settings $settings, Request $request) { return new Storage\InternalCache($bin, $cid_generator, $use_compression); } + } diff --git a/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryBase.php b/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryBase.php index b115c21..5171338 100644 --- a/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryBase.php +++ b/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryBase.php @@ -14,6 +14,7 @@ * A page cache factory operating before the kernel is available. */ abstract class FastPageCacheFactoryBase implements FastPageCacheFactoryInterface { + /** * Return a pre kernel page cache instance for this request. */ @@ -70,4 +71,5 @@ protected function getCacheControl(Settings $settings, Request $request) { return new CacheControl\NoCache(); } } + } diff --git a/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryInterface.php b/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryInterface.php index a423fa2..b524949 100644 --- a/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryInterface.php +++ b/core/lib/Drupal/Core/PageCache/FastPageCacheFactoryInterface.php @@ -14,8 +14,10 @@ * A page cache factory operating before the kernel is available. */ interface FastPageCacheFactoryInterface { + /** * Return a pre kernel page cache instance for this request. */ public function getFastPageCache(Settings $settings, Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/PageCacheBase.php b/core/lib/Drupal/Core/PageCache/PageCacheBase.php index fa04cbd..64946af 100644 --- a/core/lib/Drupal/Core/PageCache/PageCacheBase.php +++ b/core/lib/Drupal/Core/PageCache/PageCacheBase.php @@ -14,6 +14,7 @@ * Base class for page cache implementations. */ class PageCacheBase implements PageCacheInterface { + /** * TRUE when current request can be saved to the cache, FALSE otherwise. * @@ -180,4 +181,5 @@ protected function prepareCachePass(Response $response, Request $request) { $cache_control = $this->getCacheControl() ?: new CacheControl\NoCache(); $cache_control->setNotCacheable($response, $request); } + } diff --git a/core/lib/Drupal/Core/PageCache/PageCacheFactoryBase.php b/core/lib/Drupal/Core/PageCache/PageCacheFactoryBase.php index 4752bff..da53c73 100644 --- a/core/lib/Drupal/Core/PageCache/PageCacheFactoryBase.php +++ b/core/lib/Drupal/Core/PageCache/PageCacheFactoryBase.php @@ -14,6 +14,7 @@ * A page cache factory operating before the kernel exists. */ abstract class PageCacheFactoryBase implements PageCacheFactoryInterface { + /** * {@inheritdoc} */ @@ -44,4 +45,5 @@ protected function getPageCacheHelper() { * A page cache implementation. */ protected abstract function getModestPageCache(); + } diff --git a/core/lib/Drupal/Core/PageCache/PageCacheFactoryInterface.php b/core/lib/Drupal/Core/PageCache/PageCacheFactoryInterface.php index 747cc12..40de240 100644 --- a/core/lib/Drupal/Core/PageCache/PageCacheFactoryInterface.php +++ b/core/lib/Drupal/Core/PageCache/PageCacheFactoryInterface.php @@ -11,6 +11,7 @@ * A page cache factory operating before the kernel is available. */ interface PageCacheFactoryInterface { + /** * Return page cache instance. * @@ -21,4 +22,5 @@ * A page cache implementation. */ public function getPageCache(); + } diff --git a/core/lib/Drupal/Core/PageCache/PageCacheHelper.php b/core/lib/Drupal/Core/PageCache/PageCacheHelper.php index 502839a..8c2a5ba 100644 --- a/core/lib/Drupal/Core/PageCache/PageCacheHelper.php +++ b/core/lib/Drupal/Core/PageCache/PageCacheHelper.php @@ -21,6 +21,7 @@ * container. */ class PageCacheHelper { + /** * Singleton instance of pre-kernel page cache service. * @@ -110,4 +111,5 @@ public function recordAndDeliver(PageCacheInterface $page_cache, Response $respo protected function deliver(Response $response, Request $request) { $response->prepare($request)->send(); } + } diff --git a/core/lib/Drupal/Core/PageCache/PageCacheInterface.php b/core/lib/Drupal/Core/PageCache/PageCacheInterface.php index 1abee59..adf75ff 100644 --- a/core/lib/Drupal/Core/PageCache/PageCacheInterface.php +++ b/core/lib/Drupal/Core/PageCache/PageCacheInterface.php @@ -14,6 +14,7 @@ * Look up requests in the page cache and record responses. */ interface PageCacheInterface { + /** * Try to retrieve a page from the cache and return the response object. * @@ -48,4 +49,5 @@ public function setNotCacheable(); * Return TRUE when the response to the current request is cacheable. */ public function isCacheable(); + } diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/DenyCommandLineOrUnsafeMethod.php b/core/lib/Drupal/Core/PageCache/PolicyRule/DenyCommandLineOrUnsafeMethod.php index 351b36c..4f1b466 100644 --- a/core/lib/Drupal/Core/PageCache/PolicyRule/DenyCommandLineOrUnsafeMethod.php +++ b/core/lib/Drupal/Core/PageCache/PolicyRule/DenyCommandLineOrUnsafeMethod.php @@ -24,6 +24,7 @@ * internal page cache when DenyOpenSessionPolicy evaluates to TRUE. */ class DenyCommandLineOrUnsafeMethod implements PolicyRuleInterface { + /** * {@inheritdoc} */ @@ -37,4 +38,5 @@ public function apply(Request $request) { protected function isNotCLIRequest(Request $request) { return !drupal_is_cli(); } + } diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/DenyOpenSession.php b/core/lib/Drupal/Core/PageCache/PolicyRule/DenyOpenSession.php index c9e83ad..2a8f350 100644 --- a/core/lib/Drupal/Core/PageCache/PolicyRule/DenyOpenSession.php +++ b/core/lib/Drupal/Core/PageCache/PolicyRule/DenyOpenSession.php @@ -19,10 +19,12 @@ * that should not be cached and displayed to other users. */ class DenyOpenSession implements PolicyRuleInterface { + /** * {@inheritdoc} */ public function apply(Request $request) { return !$request->cookies->has(session_name()); } + } diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/InternalCacheConfig.php b/core/lib/Drupal/Core/PageCache/PolicyRule/InternalCacheConfig.php deleted file mode 100644 index 3094e86..0000000 --- a/core/lib/Drupal/Core/PageCache/PolicyRule/InternalCacheConfig.php +++ /dev/null @@ -1,42 +0,0 @@ -config = $config_factory->get('system.performance'); - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request) { - return $this->config->get('cache.page.use_internal'); - } -} diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/MaxAgeConfig.php b/core/lib/Drupal/Core/PageCache/PolicyRule/MaxAgeConfig.php deleted file mode 100644 index 8e7ceff..0000000 --- a/core/lib/Drupal/Core/PageCache/PolicyRule/MaxAgeConfig.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config_factory->get('system.performance'); - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request) { - return $this->config->get('cache.page.max_age') > 0; - } -} diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/RequireInternalCacheConfig.php b/core/lib/Drupal/Core/PageCache/PolicyRule/RequireInternalCacheConfig.php new file mode 100644 index 0000000..7de86c1 --- /dev/null +++ b/core/lib/Drupal/Core/PageCache/PolicyRule/RequireInternalCacheConfig.php @@ -0,0 +1,44 @@ +config = $config_factory->get('system.performance'); + } + + /** + * {@inheritdoc} + */ + public function apply(Request $request) { + return $this->config->get('cache.page.use_internal'); + } + +} diff --git a/core/lib/Drupal/Core/PageCache/PolicyRule/RequireMaxAgeConfig.php b/core/lib/Drupal/Core/PageCache/PolicyRule/RequireMaxAgeConfig.php new file mode 100644 index 0000000..635021f --- /dev/null +++ b/core/lib/Drupal/Core/PageCache/PolicyRule/RequireMaxAgeConfig.php @@ -0,0 +1,43 @@ +config = $config_factory->get('system.performance'); + } + + /** + * {@inheritdoc} + */ + public function apply(Request $request) { + return $this->config->get('cache.page.max_age') > 0; + } + +} diff --git a/core/lib/Drupal/Core/PageCache/PolicyRuleInterface.php b/core/lib/Drupal/Core/PageCache/PolicyRuleInterface.php index 1db0213..5a8c631 100644 --- a/core/lib/Drupal/Core/PageCache/PolicyRuleInterface.php +++ b/core/lib/Drupal/Core/PageCache/PolicyRuleInterface.php @@ -13,6 +13,7 @@ * Defines the interface for cache policy rule implementations. */ interface PolicyRuleInterface { + /** * Apply the policy rule to the given request and return the result. * @@ -23,4 +24,5 @@ * TRUE when the policy rule allows caching for the request. */ public function apply(Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/Storage/CidGenerator.php b/core/lib/Drupal/Core/PageCache/Storage/CidGenerator.php index ee7b1f6..02ecc32 100644 --- a/core/lib/Drupal/Core/PageCache/Storage/CidGenerator.php +++ b/core/lib/Drupal/Core/PageCache/Storage/CidGenerator.php @@ -14,6 +14,7 @@ * Default page cache-id generator. */ class CidGenerator implements CidGeneratorInterface { + /** * Content negotiation service. * @@ -41,4 +42,5 @@ public function getCid(Request $request) { ); return sha1(implode(':', $cid_parts)); } + } diff --git a/core/lib/Drupal/Core/PageCache/Storage/CidGeneratorInterface.php b/core/lib/Drupal/Core/PageCache/Storage/CidGeneratorInterface.php index aae509d..c4b31d1 100644 --- a/core/lib/Drupal/Core/PageCache/Storage/CidGeneratorInterface.php +++ b/core/lib/Drupal/Core/PageCache/Storage/CidGeneratorInterface.php @@ -13,6 +13,7 @@ * Defines an interface for page cache-id generators. */ interface CidGeneratorInterface { + /** * Generate the page cache cid for a request. * @@ -23,4 +24,5 @@ * The cid for a request. */ public function getCid(Request $request); + } diff --git a/core/lib/Drupal/Core/PageCache/Storage/CompressionHelper.php b/core/lib/Drupal/Core/PageCache/Storage/CompressionHelper.php index f50cfb3..c4c1c8a 100644 --- a/core/lib/Drupal/Core/PageCache/Storage/CompressionHelper.php +++ b/core/lib/Drupal/Core/PageCache/Storage/CompressionHelper.php @@ -14,11 +14,12 @@ * Decompress a response for clients not accepting gzip encoded content. */ class CompressionHelper { + /** * Compress the response body and add appropriate headers. */ public function compress(Response $response, Request $request) { - if (extension_loaded('zlib') && !$response->headers->get('Content-Encoding')) { + if (!$response->headers->get('Content-Encoding')) { $content = $response->getContent(); if ($content) { $response->setContent(gzencode($content, 9, FORCE_GZIP)); @@ -33,10 +34,10 @@ public function compress(Response $response, Request $request) { } /** - * Uncompress a response body if necessary. + * Uncompress a response body if the client cannot handle gzipped data. */ public function uncompress(Response $response, Request $request) { - if (extension_loaded('zlib') && $response->headers->get('Content-Encoding') == 'gzip') { + if ($response->headers->get('Content-Encoding') == 'gzip') { if (strpos($request->headers->get('Accept-Encoding'), 'gzip') === FALSE) { // The client does not support compression. Decompress the content and // remove the Content-Encoding header. @@ -52,4 +53,5 @@ public function uncompress(Response $response, Request $request) { } } } + } diff --git a/core/lib/Drupal/Core/PageCache/Storage/InternalCache.php b/core/lib/Drupal/Core/PageCache/Storage/InternalCache.php index 83d8809..134b57f 100644 --- a/core/lib/Drupal/Core/PageCache/Storage/InternalCache.php +++ b/core/lib/Drupal/Core/PageCache/Storage/InternalCache.php @@ -18,6 +18,7 @@ * Cache storage backend based on the internal cache. */ class InternalCache implements StorageInterface { + /** * Cache backend for the page cache. * @@ -42,6 +43,14 @@ class InternalCache implements StorageInterface { /** * Construct a new cache backend with internal cache storage. * + * If compression is enabled, a gzipped version of the page is stored in the + * cache to avoid compressing the output on each request. The cache entry is + * unzipped in the relatively rare event that the page is requested by a + * client without gzip support. + * + * Page compression requires the PHP zlib extension + * (http://php.net/manual/ref.zlib.php). + * * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to use. * @param \Drupal\Core\PageCache\Storage\CidGeneratorInterface $cid_generator @@ -53,17 +62,11 @@ class InternalCache implements StorageInterface { public function __construct(CacheBackendInterface $cache, CidGeneratorInterface $cid_generator, $use_compression) { $this->cache = $cache; $this->cidGenerator = $cid_generator; - $this->useCompression = $use_compression; + $this->useCompression = $use_compression && extension_loaded('zlib'); } /** - * Retrieve a response object from the page cache storage. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The incoming request object. - * - * @return \Symfony\Component\HttpFoundation\Response|NULL - * A response object complete with headers and content. + * {@inheritdoc} */ public function cacheGet(Request $request) { $cid = $this->cidGenerator->getCid($request); @@ -94,21 +97,12 @@ public function cacheGet(Request $request) { } /** - * Save a response object to the page cache storage. - * - * @param \Symfony\Component\HttpFoundation\Response $response - * A response object complete with headers and content. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object the response was generated for. + * {@inheritdoc} */ public function cacheSet(Response $response, Request $request) { // Use the actual timestamp from an Expires header, if available. - if ($date = $response->getExpires()) { - $expire = $date->getTimestamp(); - } - else { - $expire = Cache::PERMANENT; - } + $date = $response->getExpires(); + $expire = $date ? $date->getTimestamp() : Cache::PERMANENT; if ($this->useCompression) { $compression_helper = $this->getCompressionHelper(); @@ -138,7 +132,8 @@ public function cacheSet(Response $response, Request $request) { * @return \Drupal\Core\PageCache\Storage\CompressionHelper * A helper object implementing compression/uncompression of responses. */ - public function getCompressionHelper() { + protected function getCompressionHelper() { return new CompressionHelper(); } + } diff --git a/core/lib/Drupal/Core/PageCache/Storage/InternalCacheFactory.php b/core/lib/Drupal/Core/PageCache/Storage/InternalCacheFactory.php index 4a4b9f8..17d885f 100644 --- a/core/lib/Drupal/Core/PageCache/Storage/InternalCacheFactory.php +++ b/core/lib/Drupal/Core/PageCache/Storage/InternalCacheFactory.php @@ -12,9 +12,10 @@ use Symfony\Component\HttpFoundation\Request; /** - * A page cache factory operating before the kernel exists. + * A page cache storage factory for internal cache storage. */ class InternalCacheFactory { + /** * A cache bin to use as the page cache. * @@ -53,7 +54,7 @@ public function __construct(CacheBackendInterface $cache, CidGeneratorInterface } /** - * Construct pre-kernel storage implementation. + * Construct and return new storage backend. * * @return \Drupal\Core\PageCache\PageCacheInterface * A page cache implementation. @@ -61,4 +62,5 @@ public function __construct(CacheBackendInterface $cache, CidGeneratorInterface public function getInternalCache() { return new InternalCache($this->cache, $this->cidGenerator, $this->useCompression); } + } diff --git a/core/lib/Drupal/Core/PageCache/StorageInterface.php b/core/lib/Drupal/Core/PageCache/StorageInterface.php index ce9ad91..f5ae619 100644 --- a/core/lib/Drupal/Core/PageCache/StorageInterface.php +++ b/core/lib/Drupal/Core/PageCache/StorageInterface.php @@ -14,6 +14,7 @@ * Defines an interface for internal page cache storage. */ interface StorageInterface { + /** * Retrieve a response object from the page cache storage. * @@ -34,4 +35,5 @@ public function cacheGet(Request $request); * The request object the response was generated for. */ public function cacheSet(Response $response, Request $request); + } diff --git a/core/modules/toolbar/lib/Drupal/toolbar/PageCache/RequireToolbarPath.php b/core/modules/toolbar/lib/Drupal/toolbar/PageCache/RequireToolbarPath.php new file mode 100644 index 0000000..0c41610 --- /dev/null +++ b/core/modules/toolbar/lib/Drupal/toolbar/PageCache/RequireToolbarPath.php @@ -0,0 +1,28 @@ +getPathInfo(), '/toolbar/subtrees/') === 0; + } + +} diff --git a/core/modules/toolbar/lib/Drupal/toolbar/PageCache/ToolbarPathPolicyRule.php b/core/modules/toolbar/lib/Drupal/toolbar/PageCache/ToolbarPathPolicyRule.php deleted file mode 100644 index 5f10737..0000000 --- a/core/modules/toolbar/lib/Drupal/toolbar/PageCache/ToolbarPathPolicyRule.php +++ /dev/null @@ -1,26 +0,0 @@ -getPathInfo(), '/toolbar/subtrees/') === 0; - } -} diff --git a/core/modules/toolbar/toolbar.services.yml b/core/modules/toolbar/toolbar.services.yml index 8e86b7a..5db7287 100644 --- a/core/modules/toolbar/toolbar.services.yml +++ b/core/modules/toolbar/toolbar.services.yml @@ -7,7 +7,7 @@ services: factory_service: cache_factory arguments: [toolbar] toolbar.page_cache_policy.toolbar_path: - class: Drupal\toolbar\PageCache\ToolbarPathPolicyRule + class: Drupal\toolbar\PageCache\RequireToolbarPath toolbar.page_cache_selector.internal_storage: class: Drupal\Core\PageCache\DelegatePageCache\PolicyBoundStorageSelector arguments: ['@page_cache.internal_storage']