Caching Best Practices

Optimize performance with proper caching configuration

Caching Best Practices

Why Caching Matters

Every API request adds latency to your page load. Without caching:

  • Slow pages - Each visitor triggers API calls
  • Rate limits - You might hit API quotas
  • Reliability issues - If API is slow, your site is slow
  • Higher costs - Some APIs charge per request

With caching:

  • Fast pages - Data served from local cache
  • Fewer API calls - Only call when cache expires
  • Better reliability - Cache serves data even if API is temporarily slow
  • Lower costs - Reduced API usage

Choosing Cache Duration

Match cache duration to how often data changes:

Content TypeSuggested CacheReason
Weather30 min (1800s)Updates frequently but not every second
News headlines15 min (900s)Breaking news matters
Product catalog1-4 hoursProducts don't change minute by minute
Blog posts1 hour (3600s)Content updates are planned
Static data (countries, etc.)24 hoursRarely changes
Real-time data0s (no cache)Only when truly needed

The Caching Sweet Spot

Too short (< 1 min)
├── Many API calls
├── Risk of rate limiting
└── Slow page loads

Sweet spot (15 min - 4 hours)
├── Fast page loads
├── Reasonable data freshness
└── Minimal API calls

Too long (> 24 hours)
├── Very fast
├── But data may be stale
└── Users might see outdated info

Cache Warming Strategy

For critical content, consider cache warming:

  1. Time-based: Clear and refresh cache before peak hours
  2. Event-based: Manually clear cache after content updates
  3. Scheduled: Use cron jobs to refresh cache periodically
WordPress
// Example: Clear API Mapper cache via WP-CLI or cron
do_action('api_mapper_cache_cleared', 'connection_id');

When NOT to Cache

Disable or minimize caching for:

  • User-specific data - Shopping carts, personalized content
  • Real-time prices - Stock prices, live bidding
  • Availability checks - Booking systems, inventory counts
  • Authentication tokens - These should refresh independently

Multi-Layer Caching

Be aware of multiple cache layers:

  1. API Mapper cache - Stores API response
  2. YOOtheme cache - Caches rendered output
  3. Page cache plugins - Caches full HTML pages
  4. CDN cache - Caches at edge locations
  5. Browser cache - Client-side caching

When troubleshooting, clear ALL cache layers.

WordPress

Clear caches in order:

  1. API Mapper: Settings → API Mapper → Clear Cache
  2. YOOtheme: Customizer → Clear Cache
  3. Page cache plugin (WP Rocket, W3TC, etc.)
  4. CDN (Cloudflare, etc.)

Cache Debugging

If you suspect cache issues:

  1. Disable caching temporarily

    • Set cache duration to 0
    • Verify data loads correctly
  2. Check timestamps

    • Note when data was last updated at source
    • Compare with what you see on the site
  3. Use browser dev tools

    • Check network requests
    • Verify API isn't being called on every page load
  4. Re-enable caching

    • Don't leave caching disabled in production!

Was this page helpful?

On this page