Alright, after some research here are my findings:
My first approach was the obvious one: check W3TC’s FAQ section and find documentation about caching dynamic contents. This is what I found:
How do I implement fragment caching?
Edit your templates to with the following syntax to ensure that dynamic features remain so:
Example 1:
<!-- mfunc any PHP code --><!-- /mfunc -->
Example 2:
<!-- mfunc -->any PHP code<!-- /mfunc -->
Example 3:
<!--MFUNC -->
echo rand();
<!--/mfunc -->
Example 4:
<!-- mclude path/to/file.php --><!-- /mclude -->
Example 5:
<!-- mclude -->path/to/file.php<!-- /mclude -->
This feature would allow me to exclude certain portions of the page from the cache.
My plugin, as you know, offers two different ways to display the popular posts on your site: either via widget or by using the wpp_get_mostpopular page template. I didn’t find a way to just exclude the WPP widget from being cached, so I just excluded the whole sidebar by replacing <?php get_sidebar(); ?>
with <!-- mfunc get_sidebar(); --><!-- /mfunc -->
.
Similarly, to exclude the wpp_get_mostpopular() template tag:
<!-- mfunc if ( function_exists('wpp_get_mostpopular') ) wpp_get_mostpopular(); --><!-- /mfunc -->
The downside of this approach is, as you can probably tell by now, that you must manually edit each of your theme’s templates where you reference either the sidebar or the template tag to get it working.
Second approach: I researched a little bit more and found a way to programatically refresh the cache each time my plugin was called by your theme.
I’m not entirely sure about how it works (it’s a quite complex plugin!) but I believe that each time you flush W3TC’s cache it recreates all pages again. If this is the case, then this solution would mean a huge impact on your site if it has a lot of posts / pages, or if it gets a lots of daily visits, because then W3TC would be recreating its cache way too often.
So, my advice would be to go for the first approach instead. However, if you feel like trying what I did to my plugin to clear W3TC’s cache automatically I can post it here.
By the way, I couldn’t help to notice that, at the time of writing this, W3TC has not been updated for over a year. Many users at the forum are wondering if the plugin was abandoned, so I’d keep an eye on it if I were you – things could get messy if the current version breaks on a future WordPress upgrade.
(This is probably my longest post here in a while hehe)