You are here

function authcache_backend_cache_save in Authenticated User Page Caching (Authcache) 7.2

Collect document and headers and pass them to cache backends.

Return value

object A fake-cache object suitable for passing to drupal_serve_page_from_cache.

See also

drupal_page_set_cache()

Related topics

1 call to authcache_backend_cache_save()
authcache_exit in ./authcache.module
Implements hook_exit().
8 string references to 'authcache_backend_cache_save'
AuthcachePolicyTestCase::testCustomPagecaching in ./authcache.test
Test custom page caching rules (variable: authcache_pagecaching).
AuthcachePolicyTestCase::testDefaultCancelationRules in ./authcache.test
Test builtin standard cache cancelation rules.
AuthcachePolicyTestCase::testDefaultExclusionRules in ./authcache.test
Test builtin standard cache exclusion rules.
AuthcachePolicyTestCase::testOtherOptions in ./authcache.test
Test rest of custom options (authcache_http200, authcache_noajax).
AuthcacheTestBackend::testBackendInitFailures in tests/authcache.backend.test
Test multiple calls to drupal_backend_init().

... See full list

File

./authcache.cache.inc, line 114
Defines authcache aware copy of drupal_serve_page_from_cache().

Code

function authcache_backend_cache_save() {

  // Restore preferred header names based on the lower-case names returned
  // by drupal_get_http_header().
  $headers = array();
  $header_names = _drupal_set_preferred_header_name();
  foreach (drupal_get_http_header() as $name_lower => $value) {
    $headers[$header_names[$name_lower]] = $value;
  }

  // Retrieve the document body. Note that we do not call ob_get_clean() here in
  // order to allow cache-backends to access the buffer directly if necessary.
  // Only after the backend was invoked, ob_clean() is called.
  $body = ob_get_contents();

  // Check whether the current page might be compressed.
  $page_compressed = variable_get('page_compression', TRUE) && extension_loaded('zlib');
  if ($page_compressed) {
    $body = gzencode($body, 9, FORCE_GZIP);
  }

  // Invoke cache backend.
  module_invoke(authcache_backend(), 'authcache_backend_cache_save', $body, $headers, $page_compressed);

  // Remove buffer content.
  ob_clean();

  // Construct dummy cache object which is later served using
  // drupal_serve_page_from_cache.
  $cache = (object) array(
    'data' => array(
      'body' => $body,
      'headers' => $headers,
      'page_compressed' => $page_compressed,
    ),
    'created' => REQUEST_TIME,
  );
  return $cache;
}