Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Caches Involved in WordPress Sites

Toru
October 15, 2023

Understanding Caches Involved in WordPress Sites

Presentation slide from WordCamp Taiwan 2023. Held at Taipei on 14 October, 2023.

https://taiwan.wordcamp.org/2023/session/a-good-understanding-of-different-types-of-caches-involved-in-wordpress-sites/

Toru

October 15, 2023
Tweet

More Decks by Toru

Other Decks in Technology

Transcript

  1. 1. What is cache? 2. There are caches 4. Start

    from these… 3. Let’s try to classify
  2. What is cache? “Caching allows you to efficiently reuse previously

    retrieved or computed data” – Caching Overview, AWS https://aws.amazon.com/caching/
  3. What is cache? Retrieve or Compute Data May be slow!

    …or can we reuse the data? Improve it?
  4. What is cache? Retrieve or Compute Data Cache Skip this!

    Serve the data faster! Caching mechanism Save for reuse!
  5. What is cache? • Help to respond to the request

    faster • Help in handling more requests per given time • (May save some server costs) Do not… • Solve underlying fundamental performance issues. Do …
  6. 1. What is cache? 2. There are caches 4. Start

    from these… 3. Let’s try to classify
  7. Various caches Browser cache CDN cache HTTP caching Page cache

    WP Object Cache WP Transients Fragment/Partial caching PHP OPcache Memory caching e.g. Redis, Memcached
  8. Various caches • Different caches for different needs • Several

    technologies involved • Considerations and planning may be needed • Invalidation strategies… Simple concept of “reusing the data” become complex & complicated matter.
  9. 1. What is cache? 2. There are caches 4. Start

    from these… 3. Let’s try to classify
  10. Where – inside or outside? Browser cache CDN cache HTTP

    caching Page cache WP Object Cache WP Transients Fragment/Partial caching PHP OPcache Origin server Internet
  11. Where – inside or outside? Origin server Internet Cache-Control: max-age=300,

    public Cache-Control: no-cache, must-revalidate,max-age=0 • Various technologies ◦ PHP ◦ WordPress ◦ Server setup ◦ Hosting service’s special caching feature • More control • HTTP caching ◦ may be overridden by e.g. CDN • Less control ◦ “communication” is limited to achieve efficient invalidation https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching
  12. Granurality • Coarse-grained control • One big impact • Likely

    custom or 3rd party Page Fragment/Partial Object $var • Fine-grained control • Many small impact • Leverage core caching It is all about selection & combination!
  13. Enhanced by the infrastructure HTTP caching CDN cache Page cache

    WP Object Cache WP Transients PHP OPcache Does hosting support CDN? Caching mechanism built into PHP, but needs to be enabled at the server level Can be made “persistent” using memory caching added at the server level (e.g. Redis. Memcached.) Settings may be available at the server level to tweak Cache-Control value Does hosting have server level page caching?
  14. A word on plugins… • Provided/instructed by your hosting service

    ◦ To help server level caching mechanism. ◦ Usually to help “communication” • Everything else are usually ◦ Implement its own caching mechanism at the application level Check first with your hosting! Usually falls into these two…
  15. A side note on “Invalidation”... • Has a particular cache

    gone “stale”? If yes, stop serving this cache! And delete / purge / flush this cache! • Let’s regenerate this cache! - but when? ◦ Immediately? or ◦ Upon next request? Strategy need to be planed for each different cache
  16. 1. What is cache? 2. There are caches 4. Start

    from these… 3. Let’s try to classify
  17. HTTP cache & Page caching • HTTP caching ◦ “Cache-Control”

    ◦ Start with static files, then move onto dynamic… • Page caching ◦ If possible, use server level page caching mechanism ◦ Study what kind of page you can & should not page cache, and when should be invalidated
  18. Enhance with memory caching • Look for hosting which offers

    memory cache, to make WP Object Cache “persistent” • Leverage it in your custom code – with a planned invalidation strategy • WordPress 6.0~ ◦ More utilization of WP Object Cache ◦ WP_Query, WP_Term_Query, WP_User_Query
  19. PHP OPcache • Relatively simple ◦ Server level implementation ◦

    On or Off – no tweakings neeed • If site has plugins with many files bigger impact • WordPress 6.5 or later? ◦ Improve slow loading of WordPress sites with translations even faster with OPcache? https://make.wordpress.org/core/2023/07/24/i18n-performance-analysis/ https://make.wordpress.org/core/2023/09/05/call-for-testing-performant-translations/ https://wordpress.org/plugins/performant-translations/
  20. Summary • Cache do “help” – not “solve” • Keep

    in mind there are caches – not just a cache • Start studying and implementing from small, then explore – avoid just jumping onto all-in-one solution
  21. Credits Database icons created by xnimrodx - Flaticon https://www.flaticon.com/free-icons/database Ram

    icons created by xnimrodx - Flaticon https://www.flaticon.com/free-icons/ram Electronics icons created by xnimrodx - Flaticon https://www.flaticon.com/free-icons/electronics Server icons created by xnimrodx - Flaticon https://www.flaticon.com/free-icons/server