? per-bin-prefix.patch
Index: README.txt
===================================================================
RCS file: /cvs/drupal/contributions/modules/memcache/README.txt,v
retrieving revision 1.4.2.10.2.5
diff -u -r1.4.2.10.2.5 README.txt
--- README.txt	29 Jan 2009 18:01:47 -0000	1.4.2.10.2.5
+++ README.txt	1 Jun 2009 05:41:18 -0000
@@ -5,11 +5,11 @@
 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 
+1. Install the memcached binaries on your server. See
 
 http://www.lullabot.com/articles/how_install_memcache_debian_etch
 
-2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or 
+2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or
    higher or you will experience errors.
 3. Put your site into offline mode.
 4. Download and install the memcache module.
@@ -71,8 +71,8 @@
 pattern:
 
 'memcache_servers' => array(
-  host1:port => cluster, 
-  host2:port => cluster, 
+  host1:port => cluster,
+  host2:port => cluster,
   hostN:port => cluster
 )
 
@@ -136,6 +136,32 @@
   'memcache_key_prefix' => 'something_unique',
 );
 
+Sometimes it is desired to share data in various bins rather than keep them separated scrolls multiple drupal installs.
+For example you would want to share user sessions shared between sites while the rest of the site caches remain unique to that site.
+That can be accomplished using more granular control over key prefixes per bin using the following method
+# site 1
+$conf = array(
+  ...
+  'memcache_key_prefix' => array(
+    'memcache_default_key_prefix' => 'something_unique_for_site1', //Will be used for all bins that do not override default prefix
+    'cache_page'    => 'page_site1',
+    'cache_filter'  => 'filter_site1',
+    'cache_session'         => 'shared_bin_for_all_sites',  //shared bin
+  ),
+);
+#site 2
+$conf = array(
+  ...
+  'default_key_prefix' => array(
+    'memcache_default_key_prefix' => 'something_unique_for_site2', //Will be used for all bins that do not override default prefix
+    'cache_filter'  => 'filter_site2',
+    'cache_session'         => 'shared_bin_for_all_sites',  //shared bin
+  ),
+);
+
+
+
+
 ## SESSIONS ##
 
 Here is a sample config that uses memcache for sessions. Note you MUST have
@@ -172,8 +198,8 @@
 SOLUTION:
 Upgrade your PECL library to PECL package (2.2.1) (or higher).
 
-WARNING: 
-Zlib compression at the php.ini level and Memcache conflict. 
+WARNING:
+Zlib compression at the php.ini level and Memcache conflict.
 See http://drupal.org/node/273824
 
 ## MEMCACHE ADMIN ##
Index: dmemcache.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/memcache/dmemcache.inc,v
retrieving revision 1.1.2.7.2.4
diff -u -r1.1.2.7.2.4 dmemcache.inc
--- dmemcache.inc	26 Jan 2009 21:12:04 -0000	1.1.2.7.2.4
+++ dmemcache.inc	1 Jun 2009 05:41:18 -0000
@@ -66,7 +66,7 @@
       // try and grab a lock.  If we get the lock, we return FALSE instead of
       // the cached object which should cause it to be rebuilt.  If we do not
       // get the lock, we return the cached object.  The goal here is to avoid
-      // cache stampedes. 
+      // cache stampedes.
       // By default the cache stampede semaphore is held for 15 seconds.  This
       // can be adjusted by setting the memcache_stampede_semaphore variable.
       // TODO: Can we log when a sempahore expires versus being intentionally
@@ -228,7 +228,19 @@
   if (empty($prefix)) {
     $prefix = variable_get('memcache_key_prefix', '');
   }
-  $full_key = ($prefix ? $prefix. '-' : '') . $bin . '-' . $key;
 
+  $full_key = '';
+  if ( is_array($prefix) ) { //allow for granular memcache key-bin prefixes with default fallback
+    if ( isset($prefix[$bin]) ) {
+      $full_key = $prefix[$bin]. '-';  // assign key prefix per bin
+    }
+    else if ( isset($prefix['memcache_default_key_prefix']) ) {
+      $full_key = $prefix['memcache_default_key_prefix'] .'-';  //default key if bin-specific prefix was not set
+    }
+  }
+  else {
+    $full_key = ($prefix ? $prefix. '-' : '');  // old behavior where key prefix is a single string
+  }
+  $full_key .= $bin . '-' . $key;
   return urlencode($full_key);
 }
