Slide 1

Slide 1 text

Understanding Caches Involved in WordPress Sites Toru Miki WordCamp Taiwan 2023

Slide 2

Slide 2 text

Cache make your website faster…?

Slide 3

Slide 3 text

1. What is cache? 2. There are caches 4. Start from these… 3. Let’s try to classify

Slide 4

Slide 4 text

What is cache? “Caching allows you to efficiently reuse previously retrieved or computed data” – Caching Overview, AWS https://aws.amazon.com/caching/

Slide 5

Slide 5 text

What is cache? Retrieve or Compute Data May be slow! …or can we reuse the data? Improve it?

Slide 6

Slide 6 text

What is cache? Retrieve or Compute Data Cache Skip this! Serve the data faster! Caching mechanism Save for reuse!

Slide 7

Slide 7 text

What is cache?

Slide 8

Slide 8 text

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 …

Slide 9

Slide 9 text

1. What is cache? 2. There are caches 4. Start from these… 3. Let’s try to classify

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

1. What is cache? 2. There are caches 4. Start from these… 3. Let’s try to classify

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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!

Slide 16

Slide 16 text

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?

Slide 17

Slide 17 text

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…

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

1. What is cache? 2. There are caches 4. Start from these… 3. Let’s try to classify

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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/

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

https://profiles.wordpress.org/toru https://tarosky.co.jp/

Slide 25

Slide 25 text

Thank you! 謝謝你! Toru Miki https://twitter.com/waviaei https://profiles.wordpress.org/toru/ https://torumiki.com/

Slide 26

Slide 26 text

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