Skip to main content

Views content cache

An article from ComputerMinds - Building with Drupal in the UK since 2005
12th Jun 2010

Steven Jones

Senior Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

Views is awesome. You get a ton of flexibility and power, but that comes at a price: Some of the queries that views produces are less than optimal, and the rendering of results can take a long time. Views 2.6 introduced a nice solution to some of the issues, with the introduction of caching plugins.

Views itself comes with a single cache plugin (okay, okay two if you're really counting) that is time-based. So you can say: "I don't care if I show content that's 6 hours old" and it'll handle it fine. I've been thinking for a while that there should really be a better way, if you've got a view listing blog posts, you only really need to flush the cache on that view when a new blog post is added, or and existing one is updated or deleted. After a client really needed this, I looked into it and found some code lying around in the views issue queue written by huesforalice. I cleaned it up some and created a module, presenting:

Views content cache.

Its really simple, just choose the content types you care about, and the module handles the rest!

Well, almost, trouble is, it's actually quite hard to know when a node has changed. It's easy for things on the node itself, but harder for things like comments on the node, or things like votingapi votes. If you take all of these things into account, after a while you're back to not gaining much from the caching. I expect things like this to be addressed before a stable release of the module.

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.