Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top