Share
Embed
Understanding Caches Involved in WordPress Sites
Presentation slide from WordCamp Taiwan 2023. Held at Taipei on 14 October, 2023.
Toru
October 15, 2023
Transcript
26 slides
-
1. What is cache? 2. There are caches 4. Start
from these… 3. Let’s try to classify -
What is cache? “Caching allows you to efficiently reuse previously
retrieved or computed data” – Caching Overview, AWS https://aws.amazon.com/caching/ -
What is cache? Retrieve or Compute Data May be slow!
…or can we reuse the data? Improve it? -
What is cache? Retrieve or Compute Data Cache Skip this!
Serve the data faster! Caching mechanism Save for reuse! -
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 … -
1. What is cache? 2. There are caches 4. Start
from these… 3. Let’s try to classify -
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 -
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. -
1. What is cache? 2. There are caches 4. Start
from these… 3. Let’s try to classify -
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 -
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 -
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! -
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? -
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… -
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 -
1. What is cache? 2. There are caches 4. Start
from these… 3. Let’s try to classify -
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 -
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 -
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/ -
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 -
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