Back to blog
    Header image for the article "Caching Strategy: 5 Cache Layers to Make Your Site Lightning Fast"
    Optimization06/06/20267 min

    Caching Strategy: 5 Cache Layers to Make Your Site Lightning Fast

    Want to know how your own site is doing?

    Browser cache, server cache, object cache, CDN, and opcache – combined they make your website 10x faster.

    Author: Kodulehehaldus

    Cache = Memory

    Cache stores a previously calculated result so it doesn't have to be recalculated the next time. A correctly configured cache turns a 3-second page into a 0.3-second one.

    5 Cache Layers

    1. Browser Cache

    The visitor's browser stores files locally – they won't be reloaded on the next visit.

    Cache-Control: public, max-age=31536000, immutable

    (1 year for static files)

    2. CDN Cache

    CDNs hold a copy of the server globally. The request only reaches your server if the CDN cannot provide a response.

    3. Server-side Page Cache

    Entire HTML pages are pre-generated and stored.

    WordPress plugins:

    4. Object Cache (Redis/Memcached)

    Database queries are stored in memory. Critical for active WordPress sites.

    # Redis setup on Ubuntu
    sudo apt install redis-server

    WP plugin: Redis Object Cache.

    5. PHP OPcache

    A pre-compiled version of PHP code in memory. Standard equipment in PHP 7+.

    Check: <?php phpinfo(); ?> → search for OPcache.

    Recommended config:

    opcache.enable=1
    opcache.memory_consumption=256
    opcache.max_accelerated_files=20000
    opcache.validate_timestamps=0  ; production

    Cache Invalidation

    "There are only two hard things in Computer Science: cache invalidation and naming things." – Phil Karlton.

    Rule: every content change invalidates the cache.

    Automatic

    • WordPress: WP Rocket/W3TC invalidates automatically
    • After post update
    • After comment

    Manual

    • Admin Bar → Purge cache
    • Via API call (after deployment)
    • CLI: wp cache flush

    Cache Strategy for Different Content

    ContentCache TimeStrategy
    Logo, CSS, JS1 yearVersioned URL (style.css?v=2)
    Products (E-shop)1 hourInvalidate after change
    Homepage30 minInvalidate after new post
    Cart0NO cache
    Admin0NO cache
    API endpointvariesPer route

    Measurement

    Before and after cache configuration:

    MetricWithout CacheWith Cache
    TTFB (Time to First Byte)800ms80ms
    Server CPU60%5%
    Database Queries80/pg5/pg
    Concurrent users (max)1005000+

    Common Mistakes

    1. Caching dynamic content (cart, login)
    2. Cache time too short (missing out on the main cache benefit)
    3. Old cache after update (user sees an old version)
    4. Same cache for different users (privacy risk)
    5. Same cache for mobile/desktop (responsive design solves this)

    WooCommerce Specifics

    For e-shops:

    • ❌ Do not cache: cart, checkout, my-account
    • ✅ Cache: products, categories, homepage
    • ✅ Fragment caching for dynamic parts

    Real-world Example

    Client (WooCommerce, 5000 products):

    • Before: TTFB 1.2s, page loads in 4.8s
    • After (all 5 layers): TTFB 90ms, page loads in 0.8s
    • 6x faster

    Revenue increased by 18% over the next 30 days.

    Summary

    Caching is not optional in 2026. Every missing layer costs you customers. See also:

    Our optimization service sets up all 5 layers in one week – guaranteed 50%+ speed improvement. Request a quote.

    Sources

    Join the newsletter

    Once a month, practical tips on making your website faster, more secure and easier to find on Google and in AI search.

    By subscribing you receive our newsletter. You can unsubscribe at any time from the end of every e-mail. Privacy policy

    Author

    Kodulehehaldus.com (Innov8it OÜ) – an Estonian web agency that builds, maintains and optimises websites.

    Related articles