2 Andrey “Rarst” Savchenko • Rarst.net ♦ WPSE ( s.tk/wp ) • QueryPosts.com • Composer.Rarst.net

Caching

5 Rarst.net load time • 2.0s median • 4.3s average

Apdex ( satisfied + tolerating / 2 ) / total

7 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 ) ¥₽₴

9 Gotchas of full page cache • reuse between pages • resource usage • cold cache • rewrite

10 HTTP Cache 304 Not Modified • serve page when necessary • browser & proxy cache centric symfony.com/doc/2.4/book/http_cache.html

11 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

12 Fragment cache • independent cache of page parts • high reuse between pages + async updates / serving stale

13 Gotchas of fragment cache • anonymizing • invalidation • context • locking

14 Transients API • storage • persistence • object cache support codex.wordpress.org/Transients_API

15 TLC Transients • wraps Transients API • async updates • safe locking /markjaquith/WP-TLC-Transients

16 Fragment Cache ( the plugin ) • wraps TLC Transients • “framework” plugin • bundled & external handlers /Rarst/fragment-cache

17 Plugin responsibilities • spawn update server • accept handler registrations • expose handlers as services

18 Handler responsibilities • extend base cache class • capture fragments’ data • callback, arguments, and salt

Magic is slow

21 component time menu 9% sidebar 39% gallery 47% content 5%

22 Gallery fragment handler • hijacks [gallery] shortcode • invalidated by: • shortcode arguments • post modification time • post attachments

23 component time menu 16% sidebar 72% gallery 2% content 9%

24 Widget fragment handler • hooks into: • widget_display_callback • widget_update_callback • invalidated by widget instance modified

25 component time menu 59% sidebar 4% gallery 4% content 33%

26 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

27 component time menu 9% sidebar 9% gallery 9% content 73%

28 But how much faster is it? component improvement menu ×19 sidebar ×80 gallery ×97 total w/ content ×19

29 Never just “On” a cache 1. Implement 2. Monitor 3. Profit

30 Thank you for listening! Questions? • @Rarst • The Loop ( s.tk/chat ) Rarst.net/slides/caching