When doing performance assessment for large and complex sites to assess why they are not fast or scalable, we often run into cases where modules intentionally disable the Drupal page cache.
Depending on how often it happens and for which pages, disabling the page cache can negatively impact the site's performance, be that in scalability, or speed of serving pages.
How to inspect code for page cache disabling
If you want to inspect a module to see if it disables the page cache, search its code for something like the following:
// Recommended way of disabling the cache in Drupal 7.x drupal_page_is_cacheable(FALSE);
Or:
$GLOBALS['conf']['cache'] = 0;
Or:
$GLOBALS['conf']['cache'] = CACHE_DISABLED;
Or:
$conf['cache'] = FALSE;
Modules that disable the page cache
We have found the following modules that disable the page cache in some cases:
Bibliography Module
In biblio_init(), the module disables the page cache if someone is visiting a certain URL, such as "biblio/*" or "publications/*", depending on how the module is configured.
if ($user->uid === 0) { // Prevent caching of biblio pages for anonymous users // so session variables work and thus filering works $base = variable_get('biblio_base', 'biblio'); if (drupal_match_path($_GET['q'], "$base\n$base/*")) $conf['cache'] = FALSE; }
Flag Module
This code in flag/includes/flag_handler_relationships.inc
if (array_search(DRUPAL_ANONYMOUS_RID, $flag->roles['flag']) !== FALSE) { // Disable page caching for anonymous users. drupal_page_is_cacheable(FALSE);
Or in Drupal 6.x:
if (array_search(DRUPAL_ANONYMOUS_RID, $flag->roles['flag']) !== FALSE) { // Disable page caching for anonymous users. $GLOBALS['conf']['cache'] = 0;
Invite Module
case 'user_register': // In order to prevent caching of the preset // e-mail address, we have to disable caching // for user/register. $GLOBALS['conf']['cache'] = CACHE_DISABLED;
CAPTCHA Module
The CAPTCHA module disables the cache wherever a CAPTCHA form is displayed, be that in a comment or on the login form.
This is done via the hook_element_info() which sets a callback in the function captcha_element_process().
If you find other modules that are commonly used, please post a comment below about it.
Comments
dddave (not verified)
BOTCHA also disables page
Thu, 2013/02/21 - 02:47BOTCHA also disables page cache.
Rodney Talley (not verified)
Thank you for the solution to
Tue, 2013/11/19 - 08:10Thank you for the solution to my problem. I was in fact looking for this. I was unable to find code when cache is gone
Rind (not verified)
perect
Mon, 2014/02/17 - 19:08I checked the codes,
// Recommended way of disabling the cache in Drupal 7.x
drupal_page_is_cacheable(FALSE);
they are working perfect
Muthuraman S (not verified)
I can't able to enable in cache and block_cache on my website
Sun, 2016/04/24 - 04:14Hi all,
Thanks everyone for sharing the knowledge on this topic!. It really helpful!
Currently I am facing the issue on my website, where I cant enable in cache and block_cache on performance tab in Drupal 7. I have verified the setting.php and contrib and custom modules as well. How to check where its enable via $_SESSION stuff .. Can someone guide me to resolve this issue!
Thanks!
Muthu
Pages