Quick rundown of what I'm doing: We have an alert system set up on our site through a custom module that I wrote. When we go into alert mode, several things happen including that our site's theme changes and the frontpage content changes to a listing of blog posts so we can update user's on what is going on.

What I would like to do is include within my module a call to boost to clear its database and file cache so that the site's changes will happen right away. I've been playing around with calling some different boost functions but I can't seem to get it to work. Is there a simple way to clear all of boost's cache data or even just disable boost from within my custom module?

Any help is much appreciated.

Comments

sillygwailo’s picture

There's boost_cache_clear_all() for just the file cache. You might want to write a short function, recycling code from boost_clear_cache_submit() to delete all the files and database entries (see sample below). For clearing the expired stale files, you can use boost_cache_expire_all().

function your_module_boost_clear_all() {
  if (module_exists('boost') {
    module_load_include('inc', 'boost', 'boost.admin');
    if (boost_cache_clear_all()) {
      boost_clear_cache_parallel(BOOST_PERM_FILE_PATH);
      boost_clear_cache_parallel(BOOST_PERM_GZIP_FILE_PATH);
      watchdog('your_module', 'Boost: Static page cache cleared.');
    }
    else {
      watchdog('your_module', 'Boost: Static page cache not cleared.', array(), WATCHDOG_ERROR);
    }
  }
}

/**
 * Clear the database and file cache (reset Boost)
 *
 * Based on code from boost_clear_cache_submit()
 */
function your_module_boost_cache_reset() {
  if (module_exists('boost') && boost_cache_clear_all()) {
    db_query("TRUNCATE {boost_cache}");
    db_query("TRUNCATE {boost_cache_settings}");
    db_query("TRUNCATE {boost_cache_relationships}");
    db_query("TRUNCATE {boost_crawler}");
    _boost_rmdir_rf(BOOST_ROOT_CACHE_DIR, TRUE, TRUE, TRUE);
    watchdog('your_module', 'Boost: Static page cache & 4 database tables cleared.');
  }
  else {
    watchdog('your_module', 'Boost: Static page cache & database tables NOT cleared', array(), WATCHDOG_ERROR);
  }
}
sillygwailo’s picture

To disable the Boost cache, you can simply set its variable:

  variable_set('boost_enabled', CACHE_DISABLED);

To enable it again:

  variable_set('boost_enabled', CACHE_NORMAL);

You'll probably want to clear the cache beforehand. I'm not sure how the .htaccess changes you'd still have in place would affect disabling the Boost cache.