Skip to content
Web Development14 min read

Ecommerce Caching Strategy: What to Cache, Where and for How Long

How to design ecommerce caching: CDN and page caching, APIs and product data, search, in-memory caches, invalidation, stale data and cache warming.

01

Quick answer

An ecommerce caching strategy decides what can be cached, where (browser, CDN or edge, application, data layer) and for how long. Cache static assets and images aggressively, cache public pages and API responses with short lifetimes and purge on change, treat prices and stock as volatile, never cache carts, checkout or account data in shared caches, vary caches only by coarse segments such as market and currency, invalidate by tags or events, warm caches before peaks and monitor hit ratios and stale-content incidents.

02

Where This Fits

Caching is one part of performance and scale. See website performance optimization, Shopify performance, ecommerce scalability and, for PWAs, ecommerce PWA caching.

03

Caching Layers

LayerWhat to cacheTypical control
BrowserVersioned assets, images, fontsCache-Control headers, file name hashing
CDN or edgeImages, assets, public pages, public API GETsTTLs, purge by URL or tag, stale-while-revalidate
ApplicationRendered fragments, navigation, computed data, sessionsIn-memory or distributed cache
DataExpensive queries, read replicas, search indexesQuery cache, replication, indexing pipelines
04

What Is Safe to Cache

ContentCache?Notes
Static assets and imagesYes, long-livedVersioned file names
Category and product pagesYes, short-livedPurge on product, price or stock changes
PricesBriefly, or fetch freshConfirm at cart and checkout
Stock availabilityVery brieflyConfirm before committing
Search resultsPopular queries, short-livedVary by market and filters
Cart, checkout, accountNo (shared caches)Private, per user
B2B customer pricesOnly with customer-specific keysOften better uncached at the edge
05

CDN and Page Caching

Hosted platforms cache much of the storefront at the edge. Custom and headless storefronts should render catalog pages statically or on the server with caching, use stale-while-revalidate to keep responses fast, and purge by tag when products change, so a price update clears every page showing that product.

06

API and Product Data Caching

Product APIs can be cached at the edge or in the application for public data. Cache keys must include everything that changes the response: market, currency, language, customer group. Keep TTLs short for anything containing price or availability, and invalidate on catalog events.

Pages fast, but prices sometimes wrong?

ZSpace Labs can audit your caching layers and design keys, lifetimes and invalidation that keep pages fast and data correct.

Start a Project
07

Search engines are themselves a kind of cache: indexes built from catalog data. Keep indexes updated by events, cache results for popular queries briefly, and fetch live prices and availability for result cards where accuracy matters. See site search.

08

In-Memory Caches

In custom applications, in-memory data stores such as Redis or equivalents hold sessions, rate-limit counters, computed navigation and hot query results. Set TTLs on every key, plan memory limits and eviction, and make sure the application still works (more slowly) if the cache is unavailable.

09

Invalidation

  • Time-to-live for everything, even when you also purge
  • Purge by tag (product ID, category) on change events
  • Event-driven updates from PIM, pricing and inventory
  • Versioned asset URLs instead of purging assets
  • Avoid purging everything on every change
  • Test invalidation as carefully as caching
10

Stale Data

Decide how stale each type of data may be. A product description can be minutes old; a price shown at checkout cannot. Where staleness matters, confirm at the decision point: revalidate the cart at checkout, check stock before payment and show updated totals clearly.

11

Personalization and Caching

Personalization and caching pull in opposite directions. Keep the main page cacheable and personalize small fragments client-side or with edge logic, vary caches only by coarse attributes (market, currency, language, signed in or not), and never mix personal data into shared caches. See personalization.

12

Cache Warming

After deployments, cache purges or before a sale, warm caches for top pages and API responses so the first wave of traffic does not hit the origin at once. Combine with load testing. See scalability.

13

Monitoring

  • Hit ratio by layer and route
  • Origin request rate and latency
  • Purge and invalidation volumes
  • Stale content incidents (wrong price or stock shown)
  • Cache memory and eviction rates
14

Worked Example

An illustrative scenario, not a client case: a headless store caches product pages for an hour at the edge, including prices. After a price change for a sale, some shoppers see old prices on product pages but new prices in the cart. The team keeps the page shell cached, loads price and availability from a short-lived API response, and purges pages by product tag when prices change. Pages stay fast and price mismatches stop.

15

Common Mistakes

  • Caching carts or account pages in shared caches
  • Cache keys missing currency or market
  • Long TTLs on prices
  • Purging the whole cache on every change
  • No fallback when the cache is down
  • Personalization that makes every page uncacheable

Ready to tune caching for speed and accuracy?

Talk to ZSpace Labs about performance and caching architecture, Shopify and Hydrogen performance and speed-focused CRO.

Start a Project
16

Conclusion

Good caching keeps stores fast and correct: cache what is public and stable, keep volatile data fresh, invalidate deliberately, confirm at decision points and monitor. Related: performance optimization and observability.

FAQ

Common questions.

Static assets, images, public pages such as product and category pages (with care for prices and stock), public API responses, search results for common queries, computed data such as navigation trees, and expensive database queries.

Carts, checkout, account pages, personalized content and anything that depends on the customer, unless the cache key includes everything that changes the response and the data is not sensitive.

A content delivery network caches content at edge locations close to shoppers, reducing latency and load on origin servers, and can serve images, assets and cacheable pages and API responses.

Cache the page shell and stable content, and load prices and availability separately with short lifetimes or fresh requests, or purge cached pages when prices or stock change.

Removing or updating cached data when the source changes, by time-to-live expiry, explicit purges (by URL or tag) or event-driven updates. It is the hardest part of caching.

A caching strategy where an expired response is served while a fresh one is fetched in the background, keeping pages fast while limiting staleness.

In-memory stores are useful for sessions, rate limits, computed data and hot query results in custom applications. Hosted platforms handle much caching for you. Choose based on your architecture, not by default.

Personalized content reduces cache hit rates. Keep pages cacheable and personalize fragments on the client or at the edge with care, or vary caches only by a few coarse segments such as market or currency.

Pre-loading caches before traffic arrives, such as after a deployment or before a sale, so the first visitors do not all hit the origin.

Monitor cache hit ratios by layer and route, origin load, response times, and incidents of stale or incorrect content.

Get in touch

Have a project in mind?

Whether you're building a new digital product, improving an existing website, or looking to automate part of your business — let's talk.