function _navbar_initialize_page_cache in Navbar 7
Use Drupal's page cache for navbar/subtrees/*, even for authenticated users.
This gets invoked after full bootstrap, so must duplicate some of what's done by _drupal_bootstrap_page_cache().
@todo Replace this hack with something better integrated with DrupalKernel once Drupal's page caching itself is properly integrated.
1 call to _navbar_initialize_page_cache()
- navbar_subtrees_jsonp in ./
navbar.module - Page callback: Returns the rendered subtree of each top-level navbar link.
File
- ./
navbar.module, line 204 - Administration navbar for quick access to top level administration items.
Code
function _navbar_initialize_page_cache() {
$GLOBALS['conf']['system.performance']['cache']['page']['enabled'] = TRUE;
drupal_page_is_cacheable(TRUE);
// If we have a cache, serve it.
// @see _drupal_bootstrap_page_cache()
$cache = drupal_page_get_cache();
if (is_object($cache)) {
header('X-Drupal-Cache: HIT');
// Restore the metadata cached with the page.
$_GET['q'] = $cache->data['path'];
date_default_timezone_set(drupal_get_user_timezone());
drupal_serve_page_from_cache($cache);
// We are done.
exit;
}
// Otherwise, create a new page response (that will be cached).
header('X-Drupal-Cache: MISS');
// The Expires HTTP header is the heart of the client-side HTTP caching. The
// additional server-side page cache only takes effect when the client
// accesses the callback URL again (e.g., after clearing the browser cache or
// when force-reloading a Drupal page).
$max_age = 3600 * 24 * 365;
drupal_add_http_header('Expires', gmdate(DATE_RFC1123, REQUEST_TIME + $max_age));
drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age);
}