The Need For Speed:
Caching Fundamentals
Frankie Jarrett
@fjarrett
About me
• Working with WordPress professionally since 2007
• Engineering Manager at GoDaddy
• Oversee Managed WordPress hosting products
• Working in tech remotely for 7 years
• Based in St. Joseph, Missouri
Copyright© 2018 GoDaddy Inc. All Rights Reserved.2
Why should we care about
websites being fast?
3 Copyright© 2018 GoDaddy Inc. All Rights Reserved.
• Higher user engagement
• Time is money
• Bandwidth costs
• Because Google cares
Caching is a temporary copy of
data that can be served faster
than the original source.
Copyright© 2018 GoDaddy Inc. All Rights Reserved.4
Caching Layers
(yeah, it’s complicated)
Copyright© 2018 GoDaddy Inc. All Rights Reserved.5
Transient cache
Copyright© 2018 GoDaddy Inc. All Rights Reserved.6
Key/value storage for data that should be
checked for changes on a regular interval
(expires), or is expensive to fetch (no expiration).
• Theme/plugins updates
• Filesystem directories
• News feeds
• Complex MySQL queries (no persistent object
cache)
get_transient( $key );
set_transient( $key, $value, $ttl );
delete_transient( $key );
var_export(
get_site_transient('update_plugins')
);
stdClass(
'last_checked' => 1523054292,
response => array (
'update_available' => array(
'akismet/akismet.php’ => ...
...
)
)
)
Object cache
Copyright© 2018 GoDaddy Inc. All Rights Reserved.7
Key/value cache for expensive queries made to
the MySQL database. WordPress can be
extended to make it’s object cache persistent.
• APCu
• Redis
• Memcached
wp_cache_get( $key, $group, $force );
wp_cache_set( $key, $value, $group, $ttl );
wp_cache_delete( $key, $group );
wp_cache_incr( $key, $group );
var_export( wp_cache_get() );
stdClass(
'last_checked' => 1523054292,
response => array (
'update_available' => array(
'akismet/akismet.php’ => ...
...
)
)
)
Page cache (proxy/HTTP/static)
Copyright© 2018 GoDaddy Inc. All Rights Reserved.8
Serve dynamic content as static HTML.
• Varnish
• Apache Trafficserver
• Squid Proxy
• NGINX + FastCGI
PHP OPCache
Copyright© 2018 GoDaddy Inc. All Rights Reserved.9
Store pre-interpreted PHP bytecode (opcode) in
memory.
• Preceded by APC
• Created by the Zend group
• Added to PHP core in 5.5
opcache.enable = 1
php.ini
CDN
Copyright© 2018 GoDaddy Inc. All Rights Reserved.10
Reduce network round-trip time for assets called
on a page, such as images, JavaScript and CSS.
• CloudFlare
• AWS CloudFront
• Sucuri WAF
• Akamai
• Jetpack Photon (images only)
Minification
Copyright© 2018 GoDaddy Inc. All Rights Reserved.11
Remove whitespace characters from JavaScript,
CSS, or HTML.
Some minification tools can also modify the code
to make it less redundant and use shorthand.
function sum(num1, num2) {
return num1 + num2;
}
function sum(A,B){return A+B;}
BEFORE
AFTER
Concatenation
Copyright© 2018 GoDaddy Inc. All Rights Reserved.12
Chain the contents of JavaScript and CSS files
together and fetch the asset in a single request.
Waterfall view
Copyright© 2018 GoDaddy Inc. All Rights Reserved.13

The Need For Speed: Caching Fundamentals

  • 1.
    The Need ForSpeed: Caching Fundamentals Frankie Jarrett @fjarrett
  • 2.
    About me • Workingwith WordPress professionally since 2007 • Engineering Manager at GoDaddy • Oversee Managed WordPress hosting products • Working in tech remotely for 7 years • Based in St. Joseph, Missouri Copyright© 2018 GoDaddy Inc. All Rights Reserved.2
  • 3.
    Why should wecare about websites being fast? 3 Copyright© 2018 GoDaddy Inc. All Rights Reserved. • Higher user engagement • Time is money • Bandwidth costs • Because Google cares
  • 4.
    Caching is atemporary copy of data that can be served faster than the original source. Copyright© 2018 GoDaddy Inc. All Rights Reserved.4
  • 5.
    Caching Layers (yeah, it’scomplicated) Copyright© 2018 GoDaddy Inc. All Rights Reserved.5
  • 6.
    Transient cache Copyright© 2018GoDaddy Inc. All Rights Reserved.6 Key/value storage for data that should be checked for changes on a regular interval (expires), or is expensive to fetch (no expiration). • Theme/plugins updates • Filesystem directories • News feeds • Complex MySQL queries (no persistent object cache) get_transient( $key ); set_transient( $key, $value, $ttl ); delete_transient( $key ); var_export( get_site_transient('update_plugins') ); stdClass( 'last_checked' => 1523054292, response => array ( 'update_available' => array( 'akismet/akismet.php’ => ... ... ) ) )
  • 7.
    Object cache Copyright© 2018GoDaddy Inc. All Rights Reserved.7 Key/value cache for expensive queries made to the MySQL database. WordPress can be extended to make it’s object cache persistent. • APCu • Redis • Memcached wp_cache_get( $key, $group, $force ); wp_cache_set( $key, $value, $group, $ttl ); wp_cache_delete( $key, $group ); wp_cache_incr( $key, $group ); var_export( wp_cache_get() ); stdClass( 'last_checked' => 1523054292, response => array ( 'update_available' => array( 'akismet/akismet.php’ => ... ... ) ) )
  • 8.
    Page cache (proxy/HTTP/static) Copyright©2018 GoDaddy Inc. All Rights Reserved.8 Serve dynamic content as static HTML. • Varnish • Apache Trafficserver • Squid Proxy • NGINX + FastCGI
  • 9.
    PHP OPCache Copyright© 2018GoDaddy Inc. All Rights Reserved.9 Store pre-interpreted PHP bytecode (opcode) in memory. • Preceded by APC • Created by the Zend group • Added to PHP core in 5.5 opcache.enable = 1 php.ini
  • 10.
    CDN Copyright© 2018 GoDaddyInc. All Rights Reserved.10 Reduce network round-trip time for assets called on a page, such as images, JavaScript and CSS. • CloudFlare • AWS CloudFront • Sucuri WAF • Akamai • Jetpack Photon (images only)
  • 11.
    Minification Copyright© 2018 GoDaddyInc. All Rights Reserved.11 Remove whitespace characters from JavaScript, CSS, or HTML. Some minification tools can also modify the code to make it less redundant and use shorthand. function sum(num1, num2) { return num1 + num2; } function sum(A,B){return A+B;} BEFORE AFTER
  • 12.
    Concatenation Copyright© 2018 GoDaddyInc. All Rights Reserved.12 Chain the contents of JavaScript and CSS files together and fetch the asset in a single request.
  • 13.
    Waterfall view Copyright© 2018GoDaddy Inc. All Rights Reserved.13