? boost-453426.patch
Index: boost.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v
retrieving revision 1.1.2.1.2.3.2.28
diff -u -p -r1.1.2.1.2.3.2.28 boost.admin.inc
--- boost.admin.inc	10 Jun 2009 02:54:15 -0000	1.1.2.1.2.3.2.28
+++ boost.admin.inc	10 Jun 2009 11:13:48 -0000
@@ -38,6 +38,16 @@ function boost_admin_settings($form = ar
     '#description'   => t('Static page caching is a mechanism that stores dynamically generated web pages as HTML files in a special cache directory located under the Drupal installation directory. By caching a web page in this manner, the web server can serve it out in the fastest possible manner, without invoking PHP or Drupal at all. While this does provide a significant performance and scalability boost, you should note that it could have negative usability side-effects unless your site is targeted at an audience consisting mostly of "anonymous" visitors.'),
     '#weight'        => -10,
   );
+  $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 64800, 86400, 2*86400, 3*86400, 4*86400, 5*86400, 6*86400, 604800, 2*604800, 3*604800, 4*604800, 8*604800, 16*604800), 'format_interval');
+  $period[0] = '<' . t('none') . '>';
+  $form['boost_cache_lifetime'] = array(
+    '#type' => 'select',
+    '#title' => t('Boost - Default minimum cache lifetime'),
+    '#default_value' => BOOST_CACHE_LIFETIME,
+    '#options' => $period,
+    '#description' => t('The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied. Cache lifetime gets checked on cron runs.'),
+    '#weight'        => -9,
+  );
   $form['cache'] = array(
     '#type'           => 'radios',
     '#title'          => t('Core - Database page cache'),
@@ -46,9 +56,7 @@ function boost_admin_settings($form = ar
     '#description'    => t("If boost can not or will not cache the page, then the database will try to cache it. If boost can cache the page then it will not appear in the database cache. This is the standard Drupal cache.") . $description,
     '#weight'         => -5,
   );
-  $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 64800, 86400, 2*86400, 3*86400, 4*86400, 5*86400, 6*86400, 7*86400, 14*86400, 21*86400, 28*86400), 'format_interval');
-  $period[0] = '<' . t('none') . '>';
-  $form['cache_lifetime']['#title'] = t('Default minimum cache lifetime');
+  $form['cache_lifetime']['#title'] = t('Core - Default minimum cache lifetime');
   $form['cache_lifetime']['#options'] = $period;
 
   // Cacheability settings
Index: boost.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.install,v
retrieving revision 1.2.2.1.2.3.2.11
diff -u -p -r1.2.2.1.2.3.2.11 boost.install
--- boost.install	9 Jun 2009 11:29:00 -0000	1.2.2.1.2.3.2.11
+++ boost.install	10 Jun 2009 11:13:48 -0000
@@ -37,6 +37,9 @@ function boost_disable() {
 function boost_install() {
   // Ensure that the module is loaded early in the bootstrap:
   db_query("UPDATE {system} SET weight = -90 WHERE name = '%s'", 'boost');
+
+  // Create tables.
+  drupal_install_schema('boost');
 }
 
 /**
@@ -45,6 +48,9 @@ function boost_install() {
 function boost_uninstall() {
   db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%'", 'boost');
   cache_clear_all('variables', 'cache');
+
+  // Delete tables.
+  drupal_uninstall_schema('boost');
 }
 
 /**
@@ -102,3 +108,47 @@ function boost_requirements($phase) {
   }
   return $requirements;
 }
+
+/**
+ * Implementation of hook_schema().
+ */
+function boost_schema() {
+  $schema['boost_cache'] = array(
+    'description' => t('Table for the list of the cached page'),
+    'fields' => array(
+      'filename' => array(
+        'description' => 'Path of the cached file relative to Drupal root.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        ),
+      'created' => array(
+        'description' => t('UNIX timestamp for when the page was cached.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'expire' => array(
+        'description' => t('UNIX timestamp for the expiration date of cached page.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('filename'),
+  );
+  return $schema;
+}
+
+/**
+ * Implementation of hook_update_N().
+ *
+ * Update 6100 - Install Boost Database.
+ */
+function boost_update_6100() {
+  // Create tables.
+  return drupal_install_schema('boost');
+}
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.54
diff -u -p -r1.3.2.2.2.5.2.54 boost.module
--- boost.module	10 Jun 2009 08:18:52 -0000	1.3.2.2.2.5.2.54
+++ boost.module	10 Jun 2009 11:13:48 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: boost.module,v 1.3.2.2.2.5.2.54 2009/06/10 08:18:52 mikeytown2 Exp $
+// $Id: boost.module,v 1.3.2.2.2.5.2.53 2009/06/10 02:54:15 mikeytown2 Exp $
 
 /**
  * @file
@@ -31,6 +31,8 @@ define('BOOST_HALT_ON_ERRORS',       var
 define('BOOST_ROOT_FILE',            variable_get('boost_root_file', '.boost'));
 define('BOOST_FLUSH_DIR',            variable_get('boost_flush_dir', TRUE));
 define('BOOST_CACHE_XML',            variable_get('boost_cache_xml', TRUE));
+define('BOOST_CACHE_LIFETIME',       variable_get('boost_cache_lifetime', 3600));
+define('BOOST_TIME',                 time());
 
 // This cookie is set for all authenticated users, so that they can be
 // excluded from caching (or in the future get a user-specific cached page):
@@ -190,7 +192,7 @@ function boost_form_alter(&$form, $form_
 function boost_cron() {
   if (!BOOST_ENABLED) return;
 
-  if (variable_get('boost_expire_cron', TRUE) && boost_cache_expire_all()) {
+  if (variable_get('boost_expire_cron', TRUE) && boost_cache_db_expire()) {
     watchdog('boost', 'Expired stale files from static page cache.', array(), WATCHDOG_NOTICE);
   }
 }
@@ -276,7 +278,7 @@ function boost_user($op, &$edit, &$accou
       boost_set_cookie($user);
       break;
     case 'logout':
-      boost_set_cookie($user, time() - 86400);
+      boost_set_cookie($user, BOOST_TIME - 86400);
       break;
     case 'insert':
       // TODO: create user-specific cache directory.
@@ -341,6 +343,7 @@ function boost_block($op = 'list', $delt
               }
             }
 
+            $output .= t('<br /> %count pages cached.', array('%count' => boost_count_db()));
             $block['subject'] = '';
             $block['content'] = theme('boost_cache_status', isset($ttl) ? $ttl : -1, $output);
           }
@@ -504,12 +507,14 @@ function boost_is_cached($path) {
  * Deletes all files currently in the cache.
  */
 function boost_cache_clear_all() {
+  boost_cache_clear_all_db();
   boost_cache_delete(TRUE);
   watchdog('boost', 'Flushed ALL files from static page cache.', array(), WATCHDOG_NOTICE);
 }
 
 /**
  * Deletes all expired static files currently in the cache.
+ * OLD FUNCTION
  */
 function boost_cache_expire_all() {
   boost_cache_delete(FALSE);
@@ -517,6 +522,14 @@ function boost_cache_expire_all() {
 }
 
 /**
+ * Resets all entries in database.
+ */
+function boost_cache_clear_all_db() {
+  //db_query("DELETE FROM {boost_cache}");
+  db_query("UPDATE {boost_cache} SET created = %d, expire = %d", 0, 0);
+}
+
+/**
  * Deletes files in the cache.
  */
 function boost_cache_delete($flush = FALSE) {
@@ -586,11 +599,35 @@ function boost_cache_expire($path, $wild
   }
 
   foreach ($filenames as $filename) {
+    boost_cache_kill($filename);
+  }
+  return TRUE;
+}
+
+/**
+ * Deletes cached page from file system
+ */
+function boost_cache_kill($filename) {
+  if (file_exists($filename)) {
     @unlink($filename);
-    $gz_filename = str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename) . '.gz';
-    if (file_exists($gz_filename)) {
-      @unlink($gz_filename);
-    }
+  }
+  $gz_filename = str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename) . '.gz';
+  if (file_exists($gz_filename)) {
+    @unlink($gz_filename);
+  }
+}
+
+/**
+ * Flushes all expired pages from database
+ */
+function boost_cache_db_expire() {
+  $result = db_query('SELECT filename FROM {boost_cache} WHERE created <> 0 AND expire < %d', BOOST_TIME);
+  while ($boost = db_fetch_array($result)) {
+    boost_put_db($boost['filename'], 0, 0);
+    boost_cache_kill($boost['filename']);
+  }
+  if (BOOST_FLUSH_DIR) {
+    //TO-DO: del empty dirs.
   }
   return TRUE;
 }
@@ -604,7 +641,6 @@ function boost_cache_get($path) {
       return file_get_contents($filename);
     }
   }
-
   return NULL;
 }
 
@@ -614,9 +650,9 @@ function boost_cache_get($path) {
  */
 function boost_cache_set($path, $data = '', $extension = BOOST_FILE_EXTENSION) {
   // Append the Boost footer with the relevant timestamps
-  $time = time();
+  $time = BOOST_TIME;
   $cached_at = date('Y-m-d H:i:s', $time);
-  $expires_at = date('Y-m-d H:i:s', $time + variable_get('cache_lifetime', 600));
+  $expires_at = date('Y-m-d H:i:s', $time + BOOST_CACHE_LIFETIME);
   $data = rtrim($data) . "\n" . str_replace(array('%cached_at', '%expires_at'), array($cached_at, $expires_at), BOOST_BANNER);
 
   // Invoke hook_boost_preprocess($path, $data)
@@ -638,12 +674,36 @@ function boost_cache_set($path, $data = 
     if (BOOST_GZIP) {
       boost_cache_write(str_replace(BOOST_FILE_PATH, BOOST_GZIP_FILE_PATH, $filename) . '.gz', gzencode($data, 9));
     }
+    boost_put_db($filename, BOOST_CACHE_LIFETIME);
   }
 
   return TRUE;
 }
 
 /**
+ * Puts the expiration time in the database.
+ */
+function boost_put_db($filename, $expire, $created = BOOST_TIME) {
+  $expire = $expire + $created;
+  db_query("UPDATE {boost_cache} SET created = %d, expire = %d WHERE filename = '%s'", $created, $expire, $filename);
+  if (!db_affected_rows()) {
+    @db_query("INSERT INTO {boost_cache} (filename, created, expire) VALUES ('%s', %d, %d)", $filename, $created, $expire);
+  }
+}
+
+/**
+ * Counts the number of pages in the cache.
+ */
+function boost_count_db($all = FALSE) {
+  if ($all) {
+    return db_result(db_query("SELECT COUNT(*) FROM {boost_cache}"));
+  }
+  else {
+    return db_result(db_query("SELECT COUNT(*) FROM {boost_cache} WHERE created <> 0"));
+  }
+}
+
+/**
  * Writes data to filename in an atomic operation thats compatible with older
  * versions of php (php < 5.2.4 file_put_contents() doesn't lock correctly).
  */
@@ -735,7 +795,7 @@ function boost_file_path($path, $query =
  * updated.
  */
 function boost_file_get_age($filename) {
-  return time() - filemtime($filename);
+  return BOOST_TIME - filemtime($filename);
 }
 
 /**
@@ -743,7 +803,7 @@ function boost_file_get_age($filename) {
  * seconds.
  */
 function boost_file_get_ttl($filename) {
-  return variable_get('cache_lifetime', 600) - boost_file_get_age($filename);
+  return BOOST_CACHE_LIFETIME - boost_file_get_age($filename);
 }
 
 /**
@@ -752,7 +812,7 @@ function boost_file_get_ttl($filename) {
  * settings.
  */
 function boost_file_is_expired($filename) {
-  return boost_file_get_age($filename) > variable_get('cache_lifetime', 600);
+  return boost_file_get_age($filename) > BOOST_CACHE_LIFETIME;
 }
 
 /**
@@ -762,7 +822,7 @@ function boost_file_is_expired($filename
 function boost_set_cookie($user, $expires = NULL) {
   if (!$expires) {
     $expires = ini_get('session.cookie_lifetime');
-    $expires = (!empty($expires) && is_numeric($expires)) ? time() + (int)$expires : 0;
+    $expires = (!empty($expires) && is_numeric($expires)) ? BOOST_TIME + (int)$expires : 0;
     setcookie(BOOST_COOKIE, $user->uid, $expires, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
   }
   else {
