{"id":872,"date":"2012-09-24T22:11:50","date_gmt":"2012-09-25T08:11:50","guid":{"rendered":"http:\/\/mymonkeydo.com\/?p=872"},"modified":"2012-09-24T22:11:50","modified_gmt":"2012-09-25T08:11:50","slug":"caching-with-widgets","status":"publish","type":"post","link":"https:\/\/mymonkeydo.com\/caching-with-widgets\/","title":{"rendered":"Caching With Widgets"},"content":{"rendered":"

W3 Total Cache is a great WordPress plugin that will help your Google Page Speed score and will also speed up your website. \u00a0The only problem is that it doesn’t clear the cache when widgets are updated. \u00a0So 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. \u00a0You’ll have to empty the cache on the W3 Total Cache page.<\/p>\n

WPEngine<\/a> also has a caching system that doesn’t clear the cache upon editing widgets. \u00a0This means that every time you update a widget you have to manually clear the cache. \u00a0WPEngine is a <\/span>great WordPress host<\/a>, but doing something manually isn’t good for clients.<\/span><\/p>\n

A solution is to add a function to clear the cache every time the widget is updated. \u00a0The code below covers W3 Total Cache, WP Super Cache and WPEngine. \u00a0You can copy-paste it into your functions.php or just install the\u00a0Clear Cache For Widgets<\/a> plugin.<\/p>\n

\nfunction clear_cache_for_widgets( $instance ) {\n\n\/\/ if W3 Total Cache is being used, clear the cache\nif ( function_exists( 'w3tc_pgcache_flush' ) ) {\nw3tc_pgcache_flush();\n}\n\/\/ if WP Super Cache is being used, clear the cache\nelse if ( function_exists( 'wp_cache_clean_cache' ) ) {\nglobal $file_prefix;\nwp_cache_clean_cache( $file_prefix );\n}\nelse if ( class_exists( 'WpeCommon' ) ) {\nWpeCommon::purge_memcached();\nWpeCommon::clear_maxcdn_cache();\nWpeCommon::purge_varnish_cache();\n}\n\nreturn $instance;\n}\nadd_filter( 'widget_update_callback', 'clear_cache_for_widgets', 10 );\n\n<\/pre>\n

Source:\u00a0http:\/\/scratch99.com\/wordpress\/development\/clearing-cache-when-widget-saved\/<\/a>
\n
http:\/\/wordpress.stackexchange.com\/questions\/25425\/page-cache-for-categories-not-updating-with-w3-total-cache<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[2,4],"tags":[25,53,54,64,65],"yoast_head":"\nCaching With Widgets - My Monkey Do<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mymonkeydo.com\/caching-with-widgets\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Caching With Widgets - My Monkey Do\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mymonkeydo.com\/caching-with-widgets\/\" \/>\n<meta property=\"og:site_name\" content=\"My Monkey Do\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-25T08:11:50+00:00\" \/>\n<meta name=\"author\" content=\"Webhead\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Webhead\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mymonkeydo.com\/caching-with-widgets\/\",\"url\":\"https:\/\/mymonkeydo.com\/caching-with-widgets\/\",\"name\":\"Caching With Widgets - My Monkey Do\",\"isPartOf\":{\"@id\":\"https:\/\/mymonkeydo.com\/#website\"},\"datePublished\":\"2012-09-25T08:11:50+00:00\",\"dateModified\":\"2012-09-25T08:11:50+00:00\",\"author\":{\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\"},\"breadcrumb\":{\"@id\":\"https:\/\/mymonkeydo.com\/caching-with-widgets\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mymonkeydo.com\/caching-with-widgets\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mymonkeydo.com\/caching-with-widgets\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mymonkeydo.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Caching With Widgets\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mymonkeydo.com\/#website\",\"url\":\"https:\/\/mymonkeydo.com\/\",\"name\":\"My Monkey Do\",\"description\":\"A Log of Coding Solutions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mymonkeydo.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\",\"name\":\"Webhead\",\"url\":\"https:\/\/mymonkeydo.com\/author\/corey\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Caching With Widgets - My Monkey Do","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mymonkeydo.com\/caching-with-widgets\/","og_locale":"en_US","og_type":"article","og_title":"Caching With Widgets - My Monkey Do","og_url":"https:\/\/mymonkeydo.com\/caching-with-widgets\/","og_site_name":"My Monkey Do","article_published_time":"2012-09-25T08:11:50+00:00","author":"Webhead","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Webhead","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/mymonkeydo.com\/caching-with-widgets\/","url":"https:\/\/mymonkeydo.com\/caching-with-widgets\/","name":"Caching With Widgets - My Monkey Do","isPartOf":{"@id":"https:\/\/mymonkeydo.com\/#website"},"datePublished":"2012-09-25T08:11:50+00:00","dateModified":"2012-09-25T08:11:50+00:00","author":{"@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829"},"breadcrumb":{"@id":"https:\/\/mymonkeydo.com\/caching-with-widgets\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mymonkeydo.com\/caching-with-widgets\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mymonkeydo.com\/caching-with-widgets\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mymonkeydo.com\/"},{"@type":"ListItem","position":2,"name":"Caching With Widgets"}]},{"@type":"WebSite","@id":"https:\/\/mymonkeydo.com\/#website","url":"https:\/\/mymonkeydo.com\/","name":"My Monkey Do","description":"A Log of Coding Solutions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mymonkeydo.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829","name":"Webhead","url":"https:\/\/mymonkeydo.com\/author\/corey\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/872"}],"collection":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/comments?post=872"}],"version-history":[{"count":0,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/872\/revisions"}],"wp:attachment":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/media?parent=872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/categories?post=872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/tags?post=872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}