Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Multisite

7,501 views

Published on

"The Otto & Nacin Show" at WordCamp San Francisco, on August 12, 2011, covered transients, caching, and how multisite complicates these.

  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • WPTV link: http://wordpress.tv/2011/09/07/otto-wood-andrew-nacin-the-otto-and-nacin-show/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Will this be on wordpress.tv soon? I really need more info on the switch to blog doom you mention in the slides.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Multisite

  1. 1. The Otto & Nacin ShowWordCamp San Francisco 2011August 12, 2011
  2. 2. Nacin OttoContributing Developers to WordPress Tech Ninjas at Audrey Capitalnacin@wordpress.org otto@wordpress.org@nacin @otto42
  3. 3. Transients, Caching, andthe Complexities ofMultisite(A brief overview.)
  4. 4. Basic Caching withTransients
  5. 5. Transients are ideal for:Temporary data that canexpire at will.
  6. 6. $value = get_transient( big_data );if ( false === $value ) { // do something that takes a fair amount of time $response = wp_remote_get( $url ); $value = wp_remote_retrieve_body( $response ); set_transient( big_data, $value, 60 * 60 * 24 );}echo $value;
  7. 7. $value = get_transient( big_data );if ( false === $value ) { // do something that takes a fair amount of time $response = wp_remote_get( $url ); $value = wp_remote_retrieve_body( $response ); set_transient( big_data, $value ); // this one doesnt expire, but it might anyway}echo $value;
  8. 8. Always persistent:When theres no externalobject cache, WordPressuses the options table.
  9. 9. Object Caching
  10. 10. Object caching is ideal for:Caching an object (often aquery result) to reduceoverhead.
  11. 11. $activity_object = wp_cache_get( $id, activity );if ( false === $activity_object ) { // begrudgingly fetch our object $activity_object = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->activity WHERE ID = %d", $id ) ); wp_cache_set( $id, $activity_object , activity );}// do something with $activity_object
  12. 12. Ideally persistent:Use an object cachingbackend like APC,Memcached, or WinCache.
  13. 13. Object caching is not ideal ifyou need both datapersistence and codeportability.No knowledge of the serversetup? Use transients.
  14. 14. // Cache functions can take an expiration toowp_cache_set( $id, $activity_object , activity, $expires = 0 );
  15. 15. Enter Multisite(Run.)
  16. 16. Site Transients!Well, network-wide transients.Pardon the terminology.
  17. 17. $value = get_site_transient( big_data );if ( false === $value ) { // do something that takes a fair amount of time $response = wp_remote_get( $url ); $value = wp_remote_retrieve_body( $response ); set_site_transient( big_data, $value, 86400 );}echo $value;
  18. 18. Always persistent:When theres no externalobject cache, WordPressuses the sitemeta table.
  19. 19. It works in single-site!When not running multisite,it wraps *_transient().
  20. 20. Global Cache GroupsCache groups (activity) are site-specific. Tell WordPress what isnt.
  21. 21. // WordPress core (simplified)wp_cache_add_global_groups( array( users, user_meta, site-transient, site-options, site-lookup, blog-lookup, blog-details, ));// You (not simplified)wp_cache_add_global_groups( activity );
  22. 22. As you might expect, it worksjust fine in single-site.
  23. 23. And then theresswitch_to_blog()With great power comesgreat responsibility.
  24. 24. Rule 1Dont use it.If you do, cache around it.
  25. 25. // Example is a widget with posts from another site:$posts = wp_cache_get( recent_posts, $blog_id );if ( false === $posts ) { switch_to_blog( $blog_id ); $posts = new WP_Query( . . . )->posts; wp_cache_set( $blog_id, $posts, recent_posts ); restore_current_blog(); // OMG BBQ}// do something with $posts
  26. 26. // And for some extra credit:add_action( init, function() { wp_cache_add_global_groups( recent_posts );} );add_action( save_post, function() { global $blog_id; if ( ! in_array( $blog_id, array( 1, 2 3, 4 ) ) return; wp_cache_delete( $blog_id, recent_posts ); // And for even more extra credit: $posts = new WP_Query( . . . )->posts; wp_cache_add( $blog_id, $posts, recent_posts );} );
  27. 27. Thanks! Questions?@otto42 @nacin

×