Skip to content
Snippets Groups Projects
Commit 0085972f authored by Angie Byron's avatar Angie Byron
Browse files

#557542 follow-up by catch: Fixed module_implements() caching for authenticated users.

parent 8f1ec56d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -416,12 +416,10 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) {
*/
function module_implements_write_cache() {
$implementations = &drupal_static('module_implements');
// Check whether we need to write the cache. We do not want to cache hooks,
// which are only invoked on HTTP POST requests. Maybe the page is not
// cacheable for other reasons than the HTTP request type as well, but this
// does not matter for the hook implementation cache, because nothing breaks
// if hook implementations are not cached.
if (isset($implementations['#write_cache']) && drupal_page_is_cacheable()) {
// 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($implementations['#write_cache']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD')) {
unset($implementations['#write_cache']);
cache_set('module_implements', $implementations);
}
......
......@@ -81,6 +81,24 @@ class ModuleUnitTest extends DrupalWebTestCase {
ksort($expected_values);
$this->assertIdentical($expected_values, module_list(FALSE, FALSE, TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
}
/**
* Test module_implements() caching.
*/
function testModuleImplements() {
// Clear the cache.
cache_clear_all('module_implements', 'cache');
$this->assertFalse(cache_get('module_implements'), t('The module implements cache is empty.'));
$this->drupalGet('');
$this->assertTrue(cache_get('module_implements'), t('The module implements cache is populated after requesting a page.'));
// Test again with an authenticated user.
$this->user = $this->drupalCreateUser();
$this->drupalLogin($this->user);
cache_clear_all('module_implements', 'cache');
$this->drupalGet('');
$this->assertTrue(cache_get('module_implements'), t('The module implements cache is populated after requesting a page.'));
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment