I've started playing around with beyond-core caching in D7 and saw that Cacherouter, that I used to rely on, is discontinued in D7 and being split into multiple engine-specific modules.

Filecache is about as easy to setup as file caching was in cacherouter, maybe even a little easier, but it requires that you add some extra config lines in your settings.php file. Actually, cacherouter needs that too. Apparently this is so they can avoid hitting the database to get things out of the variable table before they can serve up cached content.

Anyway, that's all great that things are easier now than they used to be but doing a quick google didn't reveal any "standard" way of getting that stuff into an installation profile. I might have missed something obvious, let me know if i did.. I had a play with dupal_rewrite_settings in my install hook, but Aegir seems to throw all that out and forces you to keep your own config in local.settings.php instead. I "adapted" the code from drupal_rewrite_settings for a simple script to write things into local.settings.php using a similar syntax to the core function but if this could be abstracted and made into something that could be automated from a profiler .info file that would be pretty cool! at least I think so.

Feel free to use and adapt this code that I wrote for a simple template profile that I use personally, the example that I'm using will setup the filecache module correctly if you have it enabled :)

/**
 * Adapted from drupal_rewrite_settings() to build something Aegir friendly
 */
function profilename_write_local_settings($settings = array()) {
  drupal_static_reset('conf_path');
  $settings_file = conf_path(FALSE) . '/' . 'local.settings.php';

    $buffer = "<?php\n\n";
    
    // Add required settings that were missing from settings.php.
    foreach ($settings as $setting => $data) {
        $buffer .= "\$$setting = " . var_export($data, TRUE) . ";\n";
    }

      $fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w');
      if ($fp && fwrite($fp, $buffer) === FALSE) {
        throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
      }

} 

/**
 * Implements hook_install()
 */
function profilename_install() {
  // Our custom setup code for anything we can't manage through the info file
  
  /* write some settings for filecache into our local settings file */
  $settings = array();
  $settings['conf[\'cache_backends\']'] = array(drupal_get_path('module', 'filecache') . '/filecache.inc');
  $settings['conf[\'cache_default_class\']'] = 'DrupalFileCache';
  $settings['conf[\'filecache_directory\']'] = '/tmp/filecache-' . substr(conf_path(), 6);

  profilename_write_local_settings($settings);
}

Comments

thedavidmeister’s picture

Btw, domain access is another good example of a module that would be useful in a profile and has its own code to add to settings.php

deciphered’s picture

I have also had a need to do this, and the Domain module use case is a very good use case, but the tricky thing is making sure that the correct approach is taken. I will take a deeper look when I can, but I'm not yet certain that this is necessarily a feature for profiler or may belong in another module.

thedavidmeister’s picture

For sites that aren't already managed by Aegir you might want to add the line to settings.php that includes local.settings.php to simplify things.