Andrey “Rarst” Savchenko
Caching
Rarst.net load time
Apdex
( satisfied + tolerating / 2 ) / total
Rarst.net apdex — 0.87
- 77% satisfied ( <4s )
- 19% tolerating ( <16s )
- 4% frustrated ( >16s )
$ € £
What is visit’s potential worth?
( ask aloud — you’ll be surprised )
¥ ₽ ₴
Gotchas of full page cache
- reuse between pages
- resource usage
- cold cache
- rewrite
HTTP Cache
304 Not Modified
- serve page when necessary
- browser & proxy cache centric
symfony.com/doc/2.4/book/http_cache.html
Edge Side Includes ( ESI )
<esi:include src="http://example.com/1.html" />
- dynamic web content assembly
- high reuse between pages
w3.org/TR/esi-lang
Fragment cache
- independent cache of page parts
- high reuse between pages
- async updates / serving stale
Gotchas of fragment cache
- anonymizing
- invalidation
- context
- locking
Transients API
- storage
- persistence
- object cache support
codex.wordpress.org/Transients_API
TLC Transients
- wraps Transients API
- async updates
- safe locking
/markjaquith/WP-TLC-Transients
Fragment Cache ( the plugin )
- wraps TLC Transients
- “framework” plugin
- bundled & external handlers
/Rarst/fragment-cache
Plugin responsibilities
- spawn update server
- accept handler registrations
- expose handlers as services
Handler responsibilities
- extend base cache class
- capture fragments’ data
- callback, arguments, and salt
Magic is slow
component |
time |
menu |
9% |
sidebar |
39% |
gallery |
47% |
content |
5% |
Gallery fragment handler
- hijacks
[gallery]
shortcode
- invalidated by:
- shortcode arguments
- post modification time
- post attachments
component |
time |
menu |
16% |
sidebar |
72% |
gallery |
2% |
content |
9% |
Widget fragment handler
- hooks into:
widget_display_callback
widget_update_callback
- invalidated by widget instance modified
component |
time |
menu |
59% |
sidebar |
4% |
gallery |
4% |
content |
33% |
Menu fragment handler
pre_wp_nav_menu
— new in 3.9!
- epic dirty hack before that:
add_filter( 'wp_get_nav_menus', '__return_empty_array' );
- invalidated by any menu modified
component |
time |
menu |
9% |
sidebar |
9% |
gallery |
9% |
content |
73% |
But how much faster is it?
component |
improvement |
menu |
×19 |
sidebar |
×80 |
gallery |
×97 |
total w/ content |
×19 |
Never just “On” a cache
- Implement
- Monitor
- Profit