How to Fix Caching for Views With Exposed Filters in Drupal 7
One of the better features of the views module in Drupal is the ability to cache your view's output. This can come in handy when your view is doing a lot of computation. Caching your view will save your server a lot of unneeded work. One of the big current drawbacks of this feature is if you enable caching for your view and you have an exposed filter, you'll run into the following scenario:
Yikes! As you can see, caching is serving up User A's result set for User B! User B just wanted to see results in North Carolina and recieved results in Oregon! This is not very helpful as-is. Thankfully, there is a handy patch to views available to you at: http://drupal.org/node/1055616. Let me go ahead and explain how to apply this patch so you can have nice cached views with exposed filters in Drupal 7.
UPDATE: Since I wrote this article, there has since been another patch released. Feel free to try and use later patches (#81 and higher) instead of #71. If you do this, be sure to fully test views' caching to the fullest you can before deploying this fix anywhere.
- Fire up a terminal and navigate to your drupal directory:
- Update the views module: with drush:
drush dl viewsor use http://yoursite.tld/admin/modules/update )
- Change to the views module directory: either
- Download the patch (I'm using #71 as it worked best for me at the time of this writing).
- Apply the patch:
patch -p1 < views-1055616-71.patch
- Clear your caches
You should now be able to test your cached view and see different results for different values entered into your exposed filters.
Much better, right? Hopefully this patch will become part of the next dev release of views, and make its way into a stable release, so this functionality will work out of the box. Happy Drupaling!