diff --git a/authcache.helpers.inc b/authcache.helpers.inc
index 6409c48..66e321f 100644
--- a/authcache.helpers.inc
+++ b/authcache.helpers.inc
@@ -362,6 +362,9 @@ function _authcache_shutdown_save_page() {
     return;
   }
 
+  // Check whether the current page might be compressed.
+  $page_compressed = variable_get('page_compression', TRUE) && extension_loaded('zlib');
+
   $cache = (object) array(
     'cid' => $key,
     'data' => array(
@@ -369,6 +372,9 @@ function _authcache_shutdown_save_page() {
       'body' => $buffer,
       'title' => drupal_get_title(),
       'headers' => array(),
+      // We need to store whether page was compressed or not,
+      // because by the time it is read, the configuration might change.
+      'page_compressed' => $page_compressed,
     ),
     'expire' => CACHE_TEMPORARY, 
     'created' => REQUEST_TIME,
@@ -385,9 +391,8 @@ function _authcache_shutdown_save_page() {
   }
 
   if ($cache->data['body']) {
-    // Check for page compression
-    if (variable_get('page_compression', TRUE) && extension_loaded('zlib')) {
-      $cache->data['body'] = gzencode($buffer, 9, FORCE_GZIP);
+    if ($page_compressed) {
+      $cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
     }
     cache_set($cache->cid, $cache->data, 'cache_page', $cache->expire); 
   } 
