diff --git a/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php index c487d1d..7a54a41 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php @@ -43,7 +43,14 @@ function __construct(ExtensionHandlerInterface $extension_handler) { public function onTerminate(PostResponseEvent $event) { module_invoke_all('exit'); drupal_cache_system_paths(); - $this->extensionHandler->writeModuleImplementationsCache(); + $request_method = $event->getRequest()->getMethod(); + // Check whether we need to write the module implementations cache. We do + // not want to cache hooks which are only invoked on HTTP POST requests + // since these do not need to be optimized as tightly, and not doing so + // keeps the cache entry smaller. + if ($request_method == 'GET' || $request_method == 'HEAD') { + $this->extensionHandler->writeModuleImplementationsCache(); + } system_run_automated_cron(); } diff --git a/core/lib/Drupal/Core/ExtensionHandler.php b/core/lib/Drupal/Core/ExtensionHandler.php index 745ed5a..e04495a 100644 --- a/core/lib/Drupal/Core/ExtensionHandler.php +++ b/core/lib/Drupal/Core/ExtensionHandler.php @@ -573,10 +573,7 @@ public function moduleHookInfo() { * Implements Drupal\Core\ExtensionHandlerInterface::moduleImplementsWriteCache(). */ public function writeModuleImplementationsCache() { - // Check whether we need to write the cache. We do not want to cache hooks - // which are only invoked on HTTP POST requests since these do not need to be - // optimized as tightly, and not doing so keeps the cache entry smaller. - if (isset($this->implementations['#write_cache']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD')) { + if (isset($this->implementations['#write_cache'])) { unset($this->implementations['#write_cache']); $this->bootstrapCache->set('module_implements', $this->implementations); }