Answer by Jeremy French for Implementation of Drupal Memcache in custom modules

Published by jeremyfrench on Mon, 01/25/2010 - 09:54

Once set up correctly the memcache module overrides the standard Drupal cache functions, so your module dosen't need to be memcache aware. It will use memcache on systems with it enabled and standard Drupal db caching elsewhere.

The memcache module requires a bit more work to enable than most other modules.

These are the broad steps you need to
take in order to use this software.
Order is important.

  1. Install the memcached binaries on your server. See How to install
    Memcache on Debian Etch or How to
    install Memcache on OSX
  2. Install the PECL memcache extension for PHP.
  3. In php.ini set memcache.hash_strategy="consistent".
  4. Put your site into offline mode.
  5. Download and install the memcache module.
  6. If you have previously been running the memcache module, run
    update.php.
  7. Apply the DRUPAL-5-cache-serialize.patch that
    comes with the module to your Drupal
    installation.
  8. Start at least one instance of memcached on your server.
  9. Edit settings.php to configure the servers, clusters and bins that
    memcache is supposed to use.
    1. Edit settings.php to include either memcache.inc or
      memcache.db.inc. For example,
      $conf['cache_inc']
      ='sites/all/modules/memcache/memcache.db.inc';
    2. Bring your site back online.

Once installed and running you can telnet to the memcache instance on your server (11211 I belive is the default port) and type get *cache-key* to see if your data has been cached.