Cache Backport ============== This module is a drop-in replacement for D6 cache.inc, using the exact D7 cache.inc file, with minor patches that allow some D7 constant usage. Installation ------------ In order to enable it, just add this line to your settings.php file: $conf['cache_inc'] = 'sites/all/modules/cache_backport/cache.inc'; Then reads the backend configuration details to enable the different backends and configure them. Backend configuration --------------------- Download each backend package you want to use. You have to download D7 packages in order to be able to use them. # download drupal7 somewhere if you want to use drush with it, here I give an # example with drush on a drupal7 source, but you could also download the # archives of these modules from drupal.org # get drupal 7 modules sources drush dl apc filecache memcache # copy the drupal 7 modules in drupal6 module directory # WARNING: YOU WONT BE ABLE TO ACTIVATE THESE MODULES, obviously # they cannot work with drupal6. But that's not a problem we only # need the sources to include the cache.inc part cp -ar drupal7/www/sites/all/modules/apc mydrupal6/www/sites/all/modules/apc_d7 cp -ar drupal7/www/sites/all/modules/filecache mydrupal6/www/sites/all/modules/filecache_d7 cp -ar drupal7/www/sites/all/modules/memcache mydrupal6/www/sites/all/modules/memcache_d7 To enable a backend, use the D7 formalism such as: $conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc'; This line, for example, will include the APC backend. Then in order to use this apc cache backend for 'cache_menu' bin: $conf['cache_class_menu'] = 'DrupalAPCCache'; Check Drupal 7 cache documentation for available bin and Cache backends names if this page gets created one day on drupal.org. If your are looking for a detailled example, checkout the configuration sample below. Complete configuration example ------------------------------ This example has actually been tested on a complex site that actually is in production. Except we only tested it on a cloned environement. Right now, it works pretty smoothly. These configurations settings should be written in your settings.php file. -- short one -- // Use our backport, therefore switches to our own database backend // per default for all bins. $conf['cache_inc'] = 'sites/all/modules/cache_backport/cache.inc'; // Register the backends we want to use. $conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc'; $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; // Use APC for 'cache_menu'. $conf['cache_class_cache_menu'] = 'DrupalAPCCache'; // Use Memcached for 'cache_page'. $conf['cache_class_cache_page'] = 'MemCacheDrupal'; -- a bigger one one -- $module_cache_backport_enabled = TRUE; // change to TRUE to enable $module_cache_backport_default = TRUE; // change to FALSE to detect subdomain // Conditional loading if ( $module_cache_backport_enabled ) { // Set domain/subdomain if ( $module_cache_backport_default ) { $module_cache_backport_domain = 'default'; } else { $module_cache_backport_domain = $_SERVER['SERVER_NAME']; } // Load the cache backport replacement for cache.inc $conf['cache_inc'] = 'sites/all/modules/cache_backport/cache.inc'; // Define cache engines: // database, given by the cache_backport module : 'DrupalDatabaseCache' $conf['cache_backends'][] = './sites/all/modules/cache_backport/database.inc'; // filecache from drupal7 : 'DrupalFileCache' $conf['cache_backends'][] = './sites/all/modules/filecache_d7/filecache.inc'; // apc from drupal7 : 'DrupalAPCCache' $conf['cache_backends'][] = './sites/all/modules/apc_d7/drupal_apc_cache.inc'; // memcache from drupal7 : 'MemCacheDrupal' $conf['cache_backends'][] = './sites/all/modules/memcache_d7/memcache.inc'; $module_cache_backport_memcache_database_inc; // Define cache bins, here's the magic, deporting several cache on the appropriate place // cache, usage/frequency/size (but may depend on your real cache contents, mode brain on) $conf['cache_default_class'] = 'DrupalDatabaseCache'; // default, any/any/any, select memcache, apc, file or db $conf['cache_class_bootstrap'] = 'DrupalAPCCache'; // bootstrap, all/every/medium, select apc > db $conf['cache_class_block'] = 'MemCacheDrupal'; // block, any/often/small, select memcache > db > file $conf['cache_class_cache'] = 'DrupalAPCCache'; // general, all/every/medium, select apc > db $conf['cache_class_content'] = 'DrupalFileCache'; // field, page/some/large, select file > memcache > db $conf['cache_class_filter'] = 'DrupalFileCache'; // filtered, page/some/large, select file > memcache > db $conf['cache_class_form'] = 'DrupalFileCache'; // block, edit/rare/medium, select file > memcache > db $conf['cache_class_menu'] = 'MemCacheDrupal'; // menu, any/often/large, select memcache > db > file $conf['cache_class_page'] = 'MemCacheDrupal'; // node, page/often/large, select memcache > file > db $conf['cache_class_pathdst'] = 'MemCacheDrupal'; // path, any/some/medium, select memcache > db > file $conf['cache_class_pathsrc'] = 'MemCacheDrupal'; // path, any/some/medium, select memcache > db > file $conf['cache_class_uc_price'] = 'MemCacheDrupal'; // multiprice, any/often/medium, select memcache > db > file $conf['cache_class_session'] = 'DrupalAPCCache'; // session, any/any/small, select apc (mono server) > memcache > db $conf['cache_class_update'] = 'DrupalFileCache'; // system, system/rare/large, select file > db $conf['cache_class_users'] = 'MemCacheDrupal'; // users, any/some/large, select memcache > file > db $conf['cache_class_views'] = 'MemCacheDrupal'; // views, any/some/large, select memcache > file > db // views data, any/often/small, select apc > db $conf['cache_class_views_data'] = 'DrupalAPCCache'; // Define File Cache settings ----------------- $conf['filecache_fast_pagecache'] = TRUE; // set TRUE to enable fast page serving $conf['filecache_directory'] = './sites/' . $module_cache_backport_domain . '/files/filecache'; // Define APC settings ------------------------ $conf['apc_show_debug'] = FALSE; // set TRUE to enable debug mode // Define Memcache settings ------------------- /* in case you use php-memcached and not php-memcache (for this one use php.ini settings) $conf['memcache_options'] = array( Memcached::OPT_BINARY_PROTOCOL => FALSE, // set TRUE to enable binary protocol when using memcached >= 1.4 Memcached::OPT_COMPRESSION => FALSE, // set FALSE to disable compression for improved performance Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, // set consistent distribution Memcached::OPT_HASH => Memcached::HASH_CRC, // set CRC32 hash method Memcached::OPT_CONNECT_TIMEOUT => 1000, // connection timeout in milliseconds Memcached::OPT_SERVER_FAILURE_LIMIT => 5, // failure limit for server connection attempts );*/ // This is not necessary if you have only 1 memcached server on default port (11211) // but could be used to map & replicate bins between several servers (see memcached module documentation) $conf['memcache_servers'] = array( '127.0.0.1:11211' => 'default', ); $conf['memcache_bins'] = array( 'cache' => 'default', 'cache_block' => 'default', //'cache_bootstrap' => 'default', //'cache_content' => 'default', //'cache_filter' => 'default', //'cache_form' => 'default', 'cache_menu' => 'default', 'cache_page' => 'default', //'cache_pathdst' => 'default', //'cache_pathsrc' => 'default', //'cache_uc_price' => 'default', 'cache_update' => 'default', 'cache_views' => 'default', 'cache_views_data' => 'default', //'session' => 'default', //'users' => 'default', ); // Define Drupal cache settings: // inactivate database connection if the cache backend doesn't need it (cache_page only) // if the page is not cached the db connection will be made later $conf['page_cache_without_database'] = TRUE; // avoid executing veryeraly hooks in case of page cached (like hook_boot) $conf['page_cache_invoke_hooks'] = TRUE; // cached page lifetime $conf['page_cache_maximum_age'] = 3600; // default lifetime for all cache entries (except form and page), if no lifetime is specified by the module $conf['cache_lifetime'] = 0; } Known working backends ---------------------- * Database (provided in this package) Has been fully rewritten to get rid of DBTNG, maintained with this package. name : 'DrupalDatabaseCache' * APC (http://drupal.org/project/apc) Works gracefully as-is. name : 'DrupalAPCCache' * File Cache (http://drupal.org/project/filecache) Works gracefully as-is. name: 'DrupalFileCache' * Memcache (http://drupal.org/project/memcache) Works using 7.x-1.0-beta3 version after you applied the provided patch (you can try the patch with later versions, it should work if the API has not changed. name : 'MemCacheDrupal' Known limitations and bugs -------------------------- You cannot use the memcache session handling. Sessions are not handled by the cache_* tables and cannot be deported on APC or memcached with this module. Using Drupal6 memcache module to deport the session on memcached may conflict with the drupal 7 memcache module cache.inc includes. So you must keep your session storage in the database. D7 backends and patches ----------------------- Backends are being developped for D7, so you have to download backend packages using the D7 version, this is important. Because they are developped for D7, some of them might use some core functions or constants that does not exist in D6. Fortunately, since caching is an early bootstrap needed mecanism, they do not rely on any high level API. APC D7 backend is known working gracefully without any modification. Memcached backend uses one variable_get() call without specifying the second argument (valid in D7, not in D6) so you'll have to patch it. For specific backend patches, see the 'patches' sub-directory contents.