• like options, but w/ expiration time • always persistent out of the box • stored in wp_options by default • stored in memory if a caching backend (APC, Memcache, XCache, etc.) is available • available since 2.8
expensive* query or request ◦ meta_query ◦ tax_query • data persistence is absolutely required** Use Transients when * operations that require high CPU usage or high latency (Identify slow queries with Debug Bar) ** ex. - when polling data from external sources
stored in PHP memory by default • ideally* persistent when a caching backend is available • similar to Transients • available since 2.0 * Success depends on server environment
$song_obj ) { $song_obj = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->songs WHERE ID = %d", $id ) ); wp_cache_set( $id, $song_obj, 'songs' ); } // do something with $song_obj Example
the cache ONLY when data is added/changed • Avoid, if possible, caching on front end page requests (instead, generate the data on an admin event*) • Design to fail gracefully (never assume that data is in the cache) * useful events: publish_post, transition_post_status, created_ {$taxonomy}, edited_{$taxonomy}