Related articles:Drupal Module Advanced application authcache-dynamic loading content tutorial
Authcache module and boost module are not the same principle, boost module is to generate static pages, so the best caching effect, the fastest. Authcache module is the use of Drupal's own caching mechanism to generate page caching, due to enter the Drupal link, so the speed does not boost cache fast, but the advantage is that you can flexibly use Php/drupal related methods, dynamic processing of data.
First, we start with the bootstrap of Drupal.
function Drupal_bootstrap ($phase = NULL, $new _phase = TRUE) {
Not drupal_static (), because does is not depend to any run-time information.
Static $phases = Array (
Drupal_bootstrap_configuration,
Drupal_bootstrap_page_cache,
Drupal_bootstrap_database,
Drupal_bootstrap_variables,
Drupal_bootstrap_session,
Drupal_bootstrap_page_header,
Drupal_bootstrap_language,
Drupal_bootstrap_full,
);
....
}
This is a few steps of Drupal's own bootstrap (DRUPAL7), from configuration to full, so that the entire Drupal is started and all the modules are loaded.
We found that there is a link called page_cache, we have to put this phase of the processing function of the complete post, so that we can better understand this piece of code.
function _drupal_bootstrap_page_cache () {
Global $user;
Allow specifying special cache handlers in settings.php, like
Using memcached or files for storing cache information.
Require_once Drupal_root. '/includes/cache.inc ';
foreach (Variable_get (' Cache_backends ', Array ()) as $include) {
Require_once Drupal_root. '/' . $include;
}
Check for a cache mode force from settings.php.
if (Variable_get (' page_cache_without_database ')) {
$cache _enabled = TRUE;
}
else {
Drupal_bootstrap (Drupal_bootstrap_variables, FALSE);
$cache _enabled = variable_get (' cache ');
}
Drupal_block_denied (IP_Address ());
If There is no sessions cookie and cache is enabled (or forced), try
To serve a cached page.
if (!isset ($_cookie[session_name ())) && $cache _enabled) {
Make sure there are a user object because its timestamp would be
Checked, Hook_boot might check for anonymous user etc.
$user = Drupal_anonymous_user ();
Get the page from the cache.
$cache = Drupal_page_get_cache ();
If There is a cached page, display it.
if (Is_object ($cache)) {
Header (' X-drupal-cache:hit ');
Restore the metadata cached with the page.
$_get[' q '] = $cache->data[' path '];
Drupal_set_title ($cache->data[' title '], Pass_through);
Date_default_timezone_set (Drupal_get_user_timezone ());
If the skipping of the bootstrap hooks is isn't enforced, call
Hook_boot.
if (Variable_get (' Page_cache_invoke_hooks ', TRUE)) {
Bootstrap_invoke_all (' Boot ');
}
Drupal_serve_page_from_cache ($cache);
If the skipping of the bootstrap hooks is isn't enforced, call
Hook_exit.
if (Variable_get (' Page_cache_invoke_hooks ', TRUE)) {
Bootstrap_invoke_all (' exit ');
}
We are done.
Exit
}
else {
Header (' X-drupal-cache:miss ');
}
}
}
When we see the bottom, exit (we are done), we know that Drupal has finished processing the request, the following environment (session, database, module, full) and other links do not start, so greatly reduce the server processing time and improve response time.
This is Drupal's own caching mechanism!!
The caching mechanism of Drupal comes with the disadvantage that it is only valid for anonymous users.
Therefore, the Authcache module appears, Authcache is the use of Drupal's own caching mechanism, to achieve the cache of logged-in users.
Continue to look at the code above, which has 3 lines, as follows:
foreach (Variable_get (' Cache_backends ', Array ()) as $include) {
Require_once Drupal_root. '/' . $include;
}
In which, when we get ' cache_backends ', we load an array variable, so we have to use Authcache in the cache phase of Drupal itself, so we have to modify this cache_backends.
If so, as shown below, when we install Authcache, we must set the following variables.
$conf [' cache_backends '] = ' sites/all/modules/authcache/authcache.cache.inc ';
$conf [' cache_backends '] = ' sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc ';
This time, we are loaded into the authcache.cache.inc and file.
Go on...
We open authcache.cache.inc, which is to define some functions.
Continue to view the Authcache_builtin.cache.inc file and see the following code:
$delivered = Authcache_builtin_cacheinc_retrieve_cache_page ();
if ($delivered) {
Exit
}
In other words, if you hit the cache at this time, enter the page content directly, no longer continue boot! This place replaces the original Drupal. Find the cache and compute the hit cache logic, using Authcache's own algorithm, depending on the user's role, using a different cache.
This is the core of Authcache!
Of course Authcache can do more, for example,
1. Depending on the user, the production of different caches (need to be processed).
2. With the authcache_p13n module, dynamic processing of some local pages, such as a block.
3. Modify some of the cached content. (will be explained in detail later)
Wait, this is authcache than boost flexible place, of course, is also a disadvantage, need to invoke a lot of PHP, database and so on, certainly more slowly than boost.