README.txt contains the following passage:

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:

In fact, there is a way to specify memcache cache handler in settings.php, using $conf['cache_backends'] variable, like this:
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';

I think this way is preferred. See includes/bootstrap.inc, lines 2147-2152 (D7 RC4):

  // Allow specifying special cache handlers in settings.php, like
  // using memcached or files for storing cache information.
  require_once DRUPAL_ROOT . '/includes/cache.inc';
  foreach (variable_get('cache_backends', array()) as $include) {
    require_once DRUPAL_ROOT . '/' . $include;
  }

Comments

jeremy’s picture

Status: Active » Needs work

When I change my configuration of settings.php as you have recommended, memcache ceases to work.

jeremy’s picture

Status: Needs work » Needs review

Ah, what does seem to work is the following two lines together:

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

That makes sense to me, agreed?

valthebald’s picture

Deal :)

danepowell’s picture

I can confirm that #2 gets the job done. By the way, the project page should be updated to reflect this information- the current instructions there don't work for Drupal 7. Or, it might be better to trim down the project page and just provide links to the latest README / INSTALLATION files for each version of memcache.

pillarsdotnet’s picture

So which of the following lines from my settings.php should be removed? Or are they all needed?

// Unlike other cache bins, 'form_state' data cannot be regenerated; already                       
// submitted user input would be lost. Use non-volatile implementations only.                      
$conf['cache_class_form_state'] = 'DrupalDatabaseCache';

$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.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_bootstrap'] = 'MemCacheDrupal';
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['memcache_servers'] = array(
  '/var/run/memcached/memcached.sock:0' => 'default',
);
$cont['memcache_bins'] = array(
  'cache' => 'default',
);
include_once './includes/cache.inc';
include_once './sites/all/modules/memcache/memcache.inc';
include_once './sites/all/modules/memcache/memcache-lock.inc';
hawksjohnd’s picture

#2 worked for me, if these generally work I suggest updating the INSTALLATION.txt and README.txt accordingly to note that those lines will work for many installations.

I tried every variation on the stock include lines resulting in WSOD every time. I was really happy to find this thread, it's the only place I've run into these instructions!

jeremy’s picture

Status: Needs review » Fixed

I've committed a cleanup to README.txt:
http://drupalcode.org/project/memcache.git/commit/7e30817

pillarsdotnet’s picture

Can I get an answer to #5 or should I copy it to a separate support request?

jeremy’s picture

@pillarsdotnet: Try replacing it ALL with just these two lines:

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

That will give you basic Memcache functionality, and you can expand it from there as necessary.

pillarsdotnet’s picture

Have you read the following issue? #512026: Move $form_state storage from cache to new state/key-value system

I believe at least the following is also needed:

$conf['cache_class_form'] = 'DrupalDatabaseCache';
pillarsdotnet’s picture

Status: Fixed » Needs work
StatusFileSize
new3.46 KB

Patch to correct the above deficiency as well as other miscellaneous typos in the README.txt file.

jeremy’s picture

Status: Needs work » Fixed

Looks good -- I committed this cleanup, and added the additional conf line to the inline examples later in the README as well:
http://drupalcode.org/project/memcache.git/commit/bb2165f

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

byrond’s picture

Sorry if I'm misunderstanding something, but should the workaround for issue #512026 be the following?

$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
pillarsdotnet’s picture

@byrond

Sorry if I'm misunderstanding something, but should the workaround for issue #512026 be the following?

$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

Yup. As is now mentioned in the README.txt file:

9. Make sure the following line also exists, to protect the special cache_form
   bin from being assigned to a volatile cache storage implementation:
     $conf['cache_class_form'] = 'DrupalDatabaseCache';
byrond’s picture

So, there's no difference between 'cache_class_form' and 'cache_class_cache_form'?

pillarsdotnet’s picture

Sorry; the version in the README is correct; the other one is not, unless you have somehow modified Drupal core. I've been confused by that myself, more than once.

byrond’s picture

Well, I'm really confused then. I haven't modified core (don't care much for kittens, but I still can't quite cross that line), but I did take a look around. The _cache_get_object function appends the $bin parameter to 'cache_class_' to determine the name of the variable that holds the cache class name.

This is what it said about the $bin parameter:

/**
 * @param $bin
 * The cache bin to store the data in. Valid core values are 'cache_block',
 * 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
 * 'cache_menu', 'cache_page', 'cache_path', 'cache_update' or 'cache' for
 * the default cache.
 */

...which means for 'cache_form', the _cache_get_object function is going to be looking for a variable named 'cache_class_cache_form'. I also looked at form.inc, and there are statements that call cache_get and cache_set with an argument of 'cache_form'. Issue #512026 seems to be talking about the bin named 'cache_form' and possibly renaming it to 'form_state', but to my knowledge that hasn't happened yet.

If I'm way off here, could someone point me to some documentation to the possible cache bins and how to define classes for them? Everything I have seen to this point states you should use a 'cache_class_' prefix and the bin name ('cache_menu', 'cache_page', and I assume 'cache_form').

byrond’s picture

Status: Closed (fixed) » Active

Reopening, as it seems other documentation instructs to use 'cache_class_cache_form' and not 'cache_class_form'...

http://drupal.org/node/797346
http://drupal.org/node/1099596#comment-4469062

Also, we are using 'cache_class_cache_form', and we get the expected behavior (memcache is not handling 'cache_form').

pillarsdotnet’s picture

StatusFileSize
new2.2 KB

Okay, I'm gonna press the "I believe" button and roll a patch (even though I don't currently use Memcache anymore) just so I can set this to "needs review" where the maintainers will actually see it.

pillarsdotnet’s picture

Status: Active » Needs review
jlporter’s picture

Bumpety bump...

I only changed my config as described in #2 and it's working now(with elasticache!).

pillarsdotnet’s picture

@jlporter: Presumably you mean #20?

Mark this RTBC if you feel the change is correct.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Change looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks!

Prague man’s picture

I apply the patch and than:

Fatal error: Class 'MemCacheDrupal' not found in ... /includes/cache.inc on line 26

pillarsdotnet’s picture

@mpark: You applied what patch, exactly?

The patch in this issue only changes README.txt, which is a non-code file and thus can not possibly cause the error you describe.

On second thought, please open up a separate issue, as your error can not possibly have any relation to a change in a README file.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Status: Closed (fixed) » Active

This instruction does not work:

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

It gives a Fatal error: Class 'MemCacheDrupal' not found in includes/cache.inc

I have to do it like this:

include_once DRUPAL_ROOT . '/includes/cache.inc';
include_once DRUPAL_ROOT . '/sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
ruloweb’s picture

Same problem than #29, same fix

helmo’s picture

Status: Active » Closed (fixed)

Fixing the README is discussed in #1536222: Update README.txt for Drupal 7, remove INSTALLATION.txt, lets not further this issue.

NenadP’s picture

I had issue mentioned in #29, include_once helps, but solved it doing it this way, without includes:

$conf['cache_backends'] = array('sites/all/modules/contrib/apc/drupal_apc_cache.inc');
$conf['cache_default_class'] = 'DrupalAPCCache';
# When using DrupalAPCCache as default or manually caching the 'cache_page' bin
# in your settings file you do not need to start the database because Drupal can
# use the APC cache for pages. Add the following code to your settings.php file
# to do so:
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
steveoriol’s picture

Same problem than #29, same fix

Bizarre, I have the issue just for one site inside a set of 5 multi-site for the same drupal instance...

gnal’s picture

If you get the error below:

"Fatal error: Class 'MemCacheDrupal' not found in ..."

check the modifications that you have made in your settings.php file.

I had added a line in settings.php for the domain module, and then the configuration settings for memcache, and that was causing the above error. Moving the domain module configuration line to the end of settings.php (after the memcache settings) solved the issue.

asb’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

According to #1536222, the README.txt is considered to be correct. Re-opening as instructed in #1536222: Update README.txt for Drupal 7, remove INSTALLATION.txt.

liam morland’s picture

I am seeing this problem. I am running 7.x-1.3-rc1. I followed the instructions in the README. I got a WSOD until I added this to the settings:

include_once DRUPAL_ROOT . '/includes/cache.inc';
include_once DRUPAL_ROOT . '/sites/all/modules/memcache/memcache.inc';
jeremy’s picture

Status: Active » Postponed (maintainer needs more info)

I am unable to duplicate. When I copy and paste the recommended configuration from the README into settings.php and test, I do not see this error. Please provide your settings.php so we can figure out what's different.

asb’s picture

[…]
/* Memcache */
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
// $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
include_once DRUPAL_ROOT . '/includes/cache.inc';
include_once DRUPAL_ROOT . '/sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['memcache_servers'] = array(
  '127.0.0.1:11211' => 'default',
  'XX.XX.XX.XX:11211' => 'default', 
);
$conf['memcache_bins'] = array(
  'cache' => 'default',
  'cache_form' => 'database',
);
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
$conf['memcache_stampede_protection'] = TRUE;
$conf['memcache_key_prefix'] = 'FOO';
$conf['memcache_key_hash_algorithm'] = 'sha1';

/* Varnish */

// Add Varnish as the page cache handler.
$conf['cache_backends'] = array('sites/all/modules/varnish/varnish.cache.inc');
// Drupal 7 does not cache pages when we invoke hooks during bootstrap. This needs
// to be disabled.
$conf['page_cache_invoke_hooks'] = FALSE;
// Replace the default page cache with varnish
$conf['cache_class_cache_page'] = 'VarnishCache';

"XX" are placeholders for online IP addresses; "FOO" is a key prefix for a live server.

jeremy’s picture

In this configuration, this line:

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

Is overwritten by a later line:

$conf['cache_backends'] = array('sites/all/modules/varnish/varnish.cache.inc');

Two possible solutions:

  1. Change the second line to be just like the first ( $conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc'; )
  2. Move the Varnish configuration to come before the memcache configuration.

If the Varnish module is recommending this configuration when defining cache_backends, I suggest you file a bug against it so other people don't run into this same problem.

asb’s picture

When I a) uncomment $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; and b) comment out the two include_once DRUPAL_ROOT lines, and c) make the change suggested in #39, possible solution no. 1, Im getting:

$ drush rf
require_once(/var/www/d7/Array): failed to open stream: No such file or directory bootstrap.inc:2376 [warning]
…
Drush command terminated abnormally due to an unrecoverable error.

If I undo the changes, the site starts working again.

The suggested possible solution no. 2 seems to work without side effects. Thanks!

jeremy’s picture

In regards to my first suggestion, it sounds like you changed:

$conf['cache_backends'] = array('sites/all/modules/varnish/varnish.cache.inc');

to:

$conf['cache_backends'][] = array('sites/all/modules/varnish/varnish.cache.inc');

Which is not correct. It should instead have been changed to:

$conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc';
jeremy’s picture

Status: Postponed (maintainer needs more info) » Fixed

If configured as documented, memcache works. Closing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.