summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-09-29 18:08:28 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-09-29 18:08:28 +0000
commit0085972f1e62162b9c010237e5bd5b9b3bfccc4a (patch)
tree06e158fc0a7339996e16ad62025c7e810923a6c5
parent8f1ec56d35004b188b176a85c89aee6db29cdc55 (diff)
downloadbrdo-0085972f1e62162b9c010237e5bd5b9b3bfccc4a.tar.gz
brdo-0085972f1e62162b9c010237e5bd5b9b3bfccc4a.tar.bz2
#557542 follow-up by catch: Fixed module_implements() caching for authenticated users.
-rw-r--r--includes/module.inc10
-rw-r--r--modules/simpletest/tests/module.test18
2 files changed, 22 insertions, 6 deletions
diff --git a/includes/module.inc b/includes/module.inc
index 1b6d04cf7..43bd83e1d 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -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);
}
diff --git a/modules/simpletest/tests/module.test b/modules/simpletest/tests/module.test
index a157c957a..059672e5c 100644
--- a/modules/simpletest/tests/module.test
+++ b/modules/simpletest/tests/module.test
@@ -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.'));
+ }
}
/**