I am building a Digg like website in WordPress.
After installing W3 Total Cache, I noticed certain elements such as number of votes (and voters ids) per post are cached even though they shouldn’t be (at least not after a user votes for an article).
I assume it is not possible to prevent specific elements in a page from being cached (or is it?), so I thought of triggering page cache refresh programmatically.
Any suggestions?
if you want to flush the cache you can do that:
the plugin has functions for that
and you just need to call it like this:
and that is basically the answer to the question in the title
“cache refresh programmatically”
Bainternet’s solution didn’t seem to work for me.
I’m successfully using this alternative snippet within a plugin, loaded at the admin_init action:
Hopefully this helps someone out there.
To flush a single page by post id in w3tc v0.9.3 I found this worked:
W3 Total Cache supports fragment caching. From FAQ:
None of the above worked for me in my plugin. However this worked! Confirmed working for version 0.9.2.4 of w3tc.
I did a
”
$wpdb->get_results( “SELECT
sb_settings
.f_fb_app_id
,sb_settings
.f_fb_secret
FROMsb_settings
” );”
and was surprised the values f_fb_secret and f_fb_app_id was the same every time. It was obviously the w3tc cacheing the result of the query. So I added a dbcache flush in my modify page for the sb_settings table.
Should you want to clear page cache, then just use w3tc_pgcache_flush instead.
Use this snippet to make sure your PHP runs regardless of whether caching is on or off. Yes, you have to write/call your function twice.
<!-- mfunc echo 'caching ON'; --><?php echo 'caching OFF'; ?><!-- /mfunc -->
(I think) this is how it works:
<!-- mfunc echo "hello?"; -->
Keep this in mind depending on how happy you are for people to see your PHP (only happens when caching is off).