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 Type | Suggested Cache | Reason |
|---|---|---|
| Weather | 30 min (1800s) | Updates frequently but not every second |
| News headlines | 15 min (900s) | Breaking news matters |
| Product catalog | 1-4 hours | Products don't change minute by minute |
| Blog posts | 1 hour (3600s) | Content updates are planned |
| Static data (countries, etc.) | 24 hours | Rarely changes |
| Real-time data | 0s (no cache) | Only when truly needed |
The Caching Sweet Spot
Cache Warming Strategy
For critical content, consider cache warming:
- Time-based: Clear and refresh cache before peak hours
- Event-based: Manually clear cache after content updates
- Scheduled: Use cron jobs to refresh cache periodically
WordPress
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:
- API Mapper cache - Stores API response
- YOOtheme cache - Caches rendered output
- Page cache plugins - Caches full HTML pages
- CDN cache - Caches at edge locations
- Browser cache - Client-side caching
When troubleshooting, clear ALL cache layers.
WordPress
Clear caches in order:
- API Mapper: Settings → API Mapper → Clear Cache
- YOOtheme: Customizer → Clear Cache
- Page cache plugin (WP Rocket, W3TC, etc.)
- CDN (Cloudflare, etc.)
Cache Debugging
If you suspect cache issues:
-
Disable caching temporarily
- Set cache duration to 0
- Verify data loads correctly
-
Check timestamps
- Note when data was last updated at source
- Compare with what you see on the site
-
Use browser dev tools
- Check network requests
- Verify API isn't being called on every page load
-
Re-enable caching
- Don't leave caching disabled in production!
Was this page helpful?