According to this article about drupal_bootstrap function, all parameters for drupal_bootstrap() run sequentially. And if we see the sequence, here first comes - DRUPAL_BOOTSTRAP_CONFIGURATION, second DRUPAL_BOOTSTRAP_PAGE_CACHE and then database (DRUPAL_BOOTSTRAP_DATABASE),

So, My question is cache is itself stored in database, so in order to serve pages from cache, a database connection is a must. Then How Drupal manages these calls sequentially?

Accordingly, DRUPAL_BOOTSTRAP_DATABASE should come before DRUPAL_BOOTSTRAP_PAGE_CACHE. If not, what is the reason?

  • I don't know the reason, but I do know that (at least in D8) you can set a cache system that doesn't rely on a db connection. – Eyal Sep 30 '16 at 14:18
  • The caching backend may not be the local database. It could be external, like memcache. – Kevin Sep 30 '16 at 15:52
  • 2
    Don't agree with the close votes on this. Rationale behind core implementation is perfectly acceptable, and can be answered definitively. – mpdonadio Sep 30 '16 at 16:56

Inside of _drupal_bootstrap_page_cache() the key bit of information is this bit of code

  if (variable_get('page_cache_without_database')) {
    $cache_enabled = TRUE;
  else {
    $cache_enabled = variable_get('cache');

The call to bootstrap DRUPAL_BOOTSTRAP_VARIABLES will also bootstrap DRUPAL_BOOTSTRAP_DATABASE because it's before variables inside of drupal_bootstrap()

What this means is if your cache doesn't require a database connection (like memcache or filecache) then you can speedup page cache hits by not connecting to the database. The linked article talks about this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.