When should I be using the Transients API?

Transients are great when you’re doing complex queries in your themes and plugins. I tend to use transients for things like menus and showing other things like Tweets from Twitter in a sidebar for example. I wouldn’t use them for absolutely everything more-so just temporary pieces of data that can be cached.

Keep in mind that if you use something like Memcached with transients, then you will notice a massive performance gain. The rule with transients is to not use them for data that should not expire as they’re really only for temporary data and keep in mind transients are not always stored in the database.

Some uses for transients:

  • Complex and custom database queries
  • WordPress navigation menus
  • Sidebar widgets that display info like; tweets, a list of recent site visitors or a Flickr photo stream
  • Caching tag clouds

This article is a very informative one with quick benchmarks showing just how transients can speed up your site and even has a couple of examples. This other article also has a few great examples of using transients which might help you understand what to use them for as well.

Leave a Comment