Knowledgebase

Caching Strategies for Developers Print

  • developersgitdeployment, developers, caching, database, php, woocommerce, cdn, webhosting
  • 0

Making an application fast.

THE LAYERS

  • Opcode caching: OPcache, which removes PHP recompilation. Enable it and forget it.
  • Object caching: storing computed results or query results in memory or a file.
  • Page caching: storing the generated HTML.
  • HTTP caching: headers telling browsers and proxies to keep copies.
  • CDN caching: static files served near visitors.

WHAT TO CACHE

Anything expensive to compute and not specific to one visitor.

Database queries that run on every page and rarely change. Rendered fragments. API responses.

WHAT NOT TO CACHE

Anything containing one visitor's data. Cart, checkout, account pages, personalised content.

Serving one visitor's data to another is the most serious caching mistake and it happens regularly.

INVALIDATION

The hard part. When the underlying data changes, the cache must be cleared, or you serve stale content.

Clear specific keys rather than everything where you can.

ON SHARED HOSTING

File-based caching works. Redis or Memcached may be available; check.

MEASURING

Cache something, measure the difference, keep it if it helped.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot