Skip to: Site menu | Main content

Developer's Quick Tip - Working with Memcache and File Uploads

As a Drupal developer and recent memcache convert, I now know the joy of speedy caching.

Memcache actually comes with 2 modules: the main memcache code as well as "memcache admin" which, as far as I can tell, is really only necessary during devlopment and testing of the site (sort of the same way the Views UI module can be disabled after a site goes live).

When using Memcache with Drupal 5.x (it hasn't been ported to 6.x yet, but there is some ongoing work), there's a big "gotcha" that has gotten me on more than one occasion - the "show memcache statistics at the bottom of each page" option on admin/settings/memcache.

This works a lot like the devel module where it provides some useful stuff at the bottom of every page, but since it attaches itself to the bottom of every Drupal page load, it can mess with some AJAX and AHAH calls.

The upload module is one place where it can wreck havoc, pretty much causing any uploads to fail (endless-barber-pole-of-death style). Disabling the statistics or the entire "memcache admin" module returns things to normal.

In looking at the memcache_admin.module code, the problem is (relatively) easy to spot - in the memcache_admin_init() function, there are a couple of cases where the statistics aren't displayed: when the user is anonymous, on update.php, and during an autocomplete AJAX call. The devel_init() function by comparison, includes a bunch more exceptions where the statistics aren't displayed "upload/js" is one of them.

I've gone ahead and created an issue for this fix, hopefully it'll make it into the next release (and prevent me from any more head-smacking). In the meantime, if you're using memcache and file uploads are failing, this could be your solution.

Submitted by michael on Fri, 10/10/2008 - 1:52pm
Filed under:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks, I had the problem and

Thanks, I had the problem and your fix worked !