Mamba Cart Fragment Optimization

Mamba reduces WooCommerce cart fragment overhead for guest visitors by caching generated fragments when it’s safe, and automatically clearing that cache on cart changes. This keeps themes that rely on classic cart fragments fast, without risking stale or personalized data.


What It Does

  • Caches cart fragments for guests with an empty cart
  • Serves cached fragments on the standard WooCommerce fragment AJAX endpoints, reducing repeated backend work
  • Automatically clears cached fragments whenever the cart changes (add/remove), keeping behavior correct

When It Applies

  • Guest users only
  • Only when the cart is empty
  • Logged-in users or guests with items in their cart are never served cached fragments — WooCommerce always handles those dynamically

Variant-Aware Cache Key

To ensure correctness across common storefront variations, the fragment cache key includes:

  • Device: desktop or mobile
  • Language: compatible with multilingual setups
  • Currency: compatible with multi-currency setups
  • WooCommerce geo hash: the v viewer hash (or the geo cookie when present and valid)

These dimensions match how themes typically customize the mini-cart UI for different audiences, without creating unnecessary key explosion.


TTL and Clearing

  • Time-to-live: 15 minutes for cached fragments
  • Auto-clear: on add-to-cart and remove-from-cart events, the cache is cleared so the next request uses fresh data
  • Scope: clearing is group-wide for simplicity and safety, ensuring no stale keys remain after a cart mutation

Why It’s Safe

  • No caching for logged-in visitors
  • No caching once a cart is present
  • Validations on the Woo geo hash prevent polluted keys
  • Short TTL plus immediate clearing on cart changes minimize any chance of outdated UI

How It Feels in Practice

  • On catalog pages for guests with an empty cart, mini-cart and header fragments load faster with fewer backend calls
  • As soon as a shopper adds an item, the cache is cleared and WooCommerce serves fresh, dynamic fragments
  • Logged-in customers and checkout flows remain fully dynamic

Copyright 2025 - Mamba


Mamba mascot