• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

Caching With Widgets

September 24, 2012 by Webhead

W3 Total Cache is a great WordPress plugin that will help your Google Page Speed score and will also speed up your website.  The only problem is that it doesn’t clear the cache when widgets are updated.  So for example if you have a custom theme with a widget on your page and you update this widget, changes are not going to be seen.  You’ll have to empty the cache on the W3 Total Cache page.

WPEngine also has a caching system that doesn’t clear the cache upon editing widgets.  This means that every time you update a widget you have to manually clear the cache.  WPEngine is a great WordPress host, but doing something manually isn’t good for clients.

A solution is to add a function to clear the cache every time the widget is updated.  The code below covers W3 Total Cache, WP Super Cache and WPEngine.  You can copy-paste it into your functions.php or just install the Clear Cache For Widgets plugin.

function clear_cache_for_widgets( $instance ) {

// if W3 Total Cache is being used, clear the cache
if ( function_exists( 'w3tc_pgcache_flush' ) ) {
w3tc_pgcache_flush();
}
// if WP Super Cache is being used, clear the cache
else if ( function_exists( 'wp_cache_clean_cache' ) ) {
global $file_prefix;
wp_cache_clean_cache( $file_prefix );
}
else if ( class_exists( 'WpeCommon' ) ) {
WpeCommon::purge_memcached();
WpeCommon::clear_maxcdn_cache();
WpeCommon::purge_varnish_cache();
}

return $instance;
}
add_filter( 'widget_update_callback', 'clear_cache_for_widgets', 10 );

Source: http://scratch99.com/wordpress/development/clearing-cache-when-widget-saved/
http://wordpress.stackexchange.com/questions/25425/page-cache-for-categories-not-updating-with-w3-total-cache

Filed Under: Coding, Plugins Tagged With: google, optimize, php, wordpress, wpengine

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools