I'd like to request the ability to clear prefixes at once. This is useful for certain setups where administrators access one instance of the site on a URL like admin.example.com, but regular users access the site on www.example.com. In my case, I am using different prefixes for each site, but would like to clear the same key on one site if it is cleared on the other. I've attached a patch that allows this.

To clear multiple prefixes at the same time, you just need to apply the patch and add the list of prefixes to be cleared to your settings.php:
$conf['memcache_prefix_clear_list'] = array('www', 'staging');

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

Status: Needs review » Active

Patch isn't attached ;)

jtsnow’s picture

FileSize
1.83 KB

Doh! Here it is.

catch’s picture

Status: Active » Needs review
jcfiala’s picture

I think this is a pretty good idea - we've just hit on a situation where we need the same sort of functionality.

Here's our patch, targeted at d7.

cyberswat’s picture

It's probably nit-picky, but I'd suggest something that doesn't use the empty() checks ... maybe something like the following would ultimately be more performant?

if ($prefix == '') {
  $prefix = variable_get('memcache_key_prefix', '');
}
if ($prefix != '') {
  $prefix .= '-';
}
jcfiala’s picture

After a bit of back and forth locally, here's an updated patch:

jcfiala’s picture

And apparently I failed to hit save after making my changes...

jcfiala’s picture

And apparently I am an idiot today.

cyberswat’s picture

I like this approach because it explicitly sets the prefix passed in to NULL so that it can't be mistaken for a legitimate cache prefix and should perform marginally better.

marcingy’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue tags: +needs backport to 6.x

The patch is for d7 so bumping to there to solve confusion.

cyberswat’s picture

if ($prefix == NULL) { should be if ($prefix === NULL) {

jcfiala’s picture

Updated the patch to reflect cyberswat's not in comment 12:

  • Jeremy committed d982b03 on 7.x-1.x
    Issue #1084448 by jcfiala, jtsnow, Jeremy: Clear multiple prefixes at...
Jeremy’s picture

Issue summary: View changes
Status: Needs review » Fixed

Sorry for the slow review.

I've rewritten the logic to use the existing prefix variable for maximum flexibility.

The feature is currently documented as follows:

It is also possible to specify multiple prefixes per bin. Only the first prefix will be used when setting/getting cache items, but all prefixes will be cleared when deleting cache items. This provides support for more complicated configurations such as a live instance and an administrative instance each with their own prefixes and therefore their own unique caches. Any time a cache item is deleted on either instance, it gets flushed on both -- thus, should an admin do something that flushes the page cache, it will appropriately get flushed on both instances. (For more discussion see the issue where support was added, https://www.drupal.org/node/1084448.) This feature is enabled when you configure prefixes as arrays within arrays. For example:

  // Live instance.
  $conf['memcache_key_prefix'] = array(
    'default' => array(
      'live_unique', // live cache prefix
      'admin_unique', // admin cache prefix
    ),
  );

The above would be the configuration of your live instance. Then, on your administrative instance you would flip the keys:

  // Administrative instance.
  $conf['memcache_key_prefix'] = array(
    'default' => array(
      'admin_unique', // admin cache prefix
      'live_unique', // live cache prefix
    ),
  );

Status: Fixed » Closed (fixed)

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