How to add support for caching plugins for my own plugin?

Is there a generic way to support caching plugins? For example to set a flag after you update an option that caching plugins watch?

For example WP Super Cache has this:

function wp_cache_clear_cache() {
    global $cache_path;
    prune_super_cache( $cache_path . 'supercache/', true );
    prune_super_cache( $cache_path, true );
}

But I will have to add custom code for each caching plugin out there. Is there a better way to do it?

My plugin has some options and prints a shortcode based on those options. Pretty standard stuff.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Is there a generic way to support caching plugins? For example to set a flag after you update an option that caching plugins watch?

No, there isn’t. On top of that, caching may not even occur in WordPress itself. E.g. Varnish, Cloudflare, etc

You will need to handle each plugin on a case by case basis.

The closest you might get, is that a caching plugin watches for post saves to update or invalidate cached results. But since you’re writing a shortcode, there is no mechanism for flushing the cache in a generic way, or indicating that a page should not be cached in WordPress. This is because WordPress does not perform page caching, so all page caching plugins have bespoke unique implementations.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x