HomeMethod

Knowledge

Web VitalsTechniquesSnippetsAnswersImpactsBottlenecks

Improper use of transients

  • Database

Problem Summary

WordPress transients cache API responses and expensive query results. Improper use includes setting expiration too long (stale data) or too short (no benefit), storing too much data, or not using them at all for expensive operations.

Performance Impact

  • Expired cache: Short expiration means repeated database queries
  • Stale data: Long expiration serves outdated content
  • Database bloat: Storing large transient data slows queries
  • No cache benefit: Missing transients means always hitting database

How to Detect

  1. Query Monitor: Shows transient get/set operations
  2. PHP profiling: Identify repeated expensive queries
  3. Database inspection: Check wp_options for large transients
  4. Debug logs: Enable WP_DEBUG to see transient operations

Solutions

1. Set Appropriate Expiration

Code
// Short for frequently changing dataset_transient('weather_data', , 15 * MINUTE_IN_SECONDS);// Medium for daily dataset_transient('daily_stats', , DAY_IN_SECONDS);// Long for static dataset_transient('site_config', , WEEK_IN_SECONDS);

2. Check Before Setting

Code
 = get_transient('my_data');if (false === ) {   = expensive_database_query();  set_transient('my_data', , HOUR_IN_SECONDS);}

3. Use Object Cache

Install Redis or Memcached for persistent object caching.

4. Delete on Updates

Code
<?php
function my_post_updated() {  delete_transient('my_cached_data');}add_action('save_post', 'my_post_updated');

5. Don’t Store Large Data

Store IDs or references, not entire objects.

Further Reading

Support our family now