Drupal Rules

I haven’t blogged in a bit, and I have a few random items I want to write up. I’m doing a lot of work with Drupal, and I’m still learning some little tricks here and there.

When I’m writing custom code, I often use Drupal’s cache. That’s pretty easy to do, with cache_set and cache_get. I recently found myself in a situation, though, where I wanted to clear a certain item from cache any time a user created or edited a node of a certain type.

It turns out to be really easy to do that with the Rules module. Just set up a rule that is triggered on insert or update of a certain node type, and make the action a simple line of PHP code:

cache_clear_all(‘your_cache_key’, ‘cache’);

Easy!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.