Hi

The documentation is a bit confusing. (which files to use/include etc.)
Through trial and error, (I think) I figured out the configuration for Drupal 7.

Can somebody inform me that the code below is correct?
Do I still need to include $conf['cache_inc'] = 'sites/all/modules/memcache/memcache.inc'; as well?

$conf['cache_inc'] = 'sites/all/modules/memcache/memcache.inc';
$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.db.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';

$conf['memcache_servers'] = array(
	'127.0.0.1:11211' => 'default',
	'127.0.0.1:11212' => 'block',
	'127.0.0.1:11213' => 'content',
	'127.0.0.1:11214' => 'filter',
	'127.0.0.1:11215' => 'form',
	'127.0.0.1:11216' => 'menu',
	'127.0.0.1:11217' => 'page',
	'127.0.0.1:11218' => 'update',
	'127.0.0.1:11219' => 'views',	    
);

$conf['memcache_bins'] = array(
	'cache' => 'default',
	'cache_block'  => 'block',
	'cache_content'  => 'content',
	'cache_filter' => 'filter',
	'cache_form'   => 'form',
	'cache_menu'   => 'menu',
	'cache_page'  => 'page',
	'cache_update' => 'update',
	'cache_views'  => 'views',
	'cache_views_data'  => 'views',
);

Regards.

Comments

flatcircle’s picture

In the installation section, I read:

Edit settings.php to include either memcache.inc or memcache.db.inc.
For example,

$conf['cache_inc'] ='sites/all/modules/memcache/memcache.db.inc';

If I use only this, will the backend also be cached or do I have to include

$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.db.inc';

as well?

Anonymous’s picture

Seems the wrong approach,

In Drupal 7+, you no longer should set cache_inc in settings.php.  Instead, you
will have to manually include 'cache.inc' and 'memcache.inc', then update $conf
to tell Drupal to default to memcache for caching:

  // the path to the core cache file
  include_once('./includes/cache.inc');
  // the path to the memcache cache file
  include_once('./sites/all/modules/memcache/memcache.inc');
  // make MemCacheDrupal the default cache class
  $conf['cache_default_class'] = 'MemCacheDrupal';
flatcircle’s picture

I thought that the variables $conf['cache_inc'], $conf['lock_inc'], $conf['cache_backends'][] =,... were D7 specific and that I had to use these.

So according to your reply. I should add the code below to my settings.php?
Can somebody confirm that this is correct for D7?

include_once('./includes/cache.inc');
include_once('./sites/all/modules/memcache/memcache.inc');
$conf['cache_default_class'] = 'MemCacheDrupal';

$conf['memcache_servers'] = array(
	'127.0.0.1:11211' => 'default',
	'127.0.0.1:11212' => 'block',
	'127.0.0.1:11213' => 'content',
	'127.0.0.1:11214' => 'filter',
	'127.0.0.1:11215' => 'form',
	'127.0.0.1:11216' => 'menu',
	'127.0.0.1:11217' => 'page',
	'127.0.0.1:11218' => 'update',
	'127.0.0.1:11219' => 'views',	    
);

$conf['memcache_bins'] = array(
	'cache' => 'default',
	'cache_block'  => 'block',
	'cache_content'  => 'content',
	'cache_filter' => 'filter',
	'cache_form'   => 'form',
	'cache_menu'   => 'menu',
	'cache_page'  => 'page',
	'cache_update' => 'update',
	'cache_views'  => 'views',
	'cache_views_data'  => 'views',
);
Anonymous’s picture

I'm using a single server:11211 and this works for me

include_once('./includes/cache.inc');
include_once('./sites/all/modules/memcache/memcache.inc');
$conf['cache_default_class'] = 'MemCacheDrupal';

Haven't tried the memcache_Server / bins options.

tomgf’s picture

I have tried this suggested configuration with success. Both the simple config and the memcache_servers and memcache_bins options (I haven't test it with specific log files – one per server – though).

The only thing I have to add – as I am running multiple websites – is this:

$conf['memcache_key_prefix'] = 'UNIQUE_TO_THIS_WEBSITE'; // i.e. host name

flatcircle’s picture

When I use:


include_once('./includes/cache.inc');
include_once('./sites/all/modules/memcache/memcache.db.inc');
$conf['cache_default_class'] = 'MemCacheDrupal';

I get the following error:

Fatal error: Cannot redeclare cache_get() (previously declared in /var/www/html/drupal7/includes/cache.inc:49) in /var/www/html/drupal7/sites/all/modules/memcache/memcache.db.inc on line 77

flatcircle’s picture

Seems like the memcache.db.inc is causing this (memcache.inc is working fine)

catch’s picture

memcache.db.inc is deprecated, you just want memcache.inc

alladdin’s picture

Status: Active » Closed (fixed)

I can confirm that configuration form #2 is working:

// the path to the core cache file
include_once('./includes/cache.inc');
// the path to the memcache cache file
include_once('./sites/all/modules/memcache/memcache.inc');
// make MemCacheDrupal the default cache class
$conf['cache_default_class'] = 'MemCacheDrupal';

muschpusch’s picture

jordanmagnuson’s picture

Status: Closed (fixed) » Active

Can one of this module's core developers confirm this again, for Drupal 7... I've seen different methods advocated in different places, and just want to make sure of the latest confirmed method of implementation.

In settings.php should we use:
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';

Or (as stated above and shown at http://drupal.org/node/1131468):

include_once('./includes/cache.inc');
include_once('./sites/all/modules/memcache/memcache.inc');

And what about memcache-lock.inc? We don't need to include that in settings.php?

markpavlitski’s picture

Status: Active » Closed (fixed)

The correct approach is to use:

$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';

If you also wish to use the memcache lock system you will need:

$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';

Here is an example default configuration in settings.php:

$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
// The 'cache_form' bin must be assigned to non-volatile storage.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

$conf['memcache_servers'] = array(
  'localhost:11211' => 'default',
);

$conf['memcache_bins'] = array(
  'cache' => 'default',
);

$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';

This will assign all cache bins to memcache with the exception of the cache_form special case which should be kept in the database to avoid issues when submitting forms.