WordPress.org

Ideas

standard wordpress action hook to clear cache for cache plugins

  1. Jose
    Inactive

    As many users know, server cache could be very nice, but sometimes a little annoying. I think it would be great to have a standard WordPress action hook and function to clear the cache. So all plugins developers could use this function and have high probability that whatever server cache plugin is active, the cache will be cleared. WordPress should pretend that cache plugins authors hook to the standard action in their plugin.

    Let's suppose we call this action "wp_clear_cache_by_all_server_cache_plugins".

    E.g. let's consider WP_SUPER_CACHE. It clears the cache with wp_cache_clear_cache(). In this case in WP Super Cache plugin we should have:

    add_action( 'wp_clear_cache_by_all_server_cache_plugins','wp_cache_clear_cache'
    function wp_cache_clear_cache(){
       ....
       //code of the plugin
      ....
    }
    
    //Or W3 Total Cache
    add_action( 'wp_clear_cache_by_all_server_cache_plugins','w3tc_pgcache_flush' );
    function w3tc_pgcache_flush(){
       ....
       //code of the plugin
      ....
    }

    Doing so, on a third plugin, you can define a function to clear the cache and if the active cache plugin has respected the standard action, the cache will be cleared:

    function clear_cache_by_third_plugin(){
       do_action( 'wp_clear_cache_by_all_server_cache_plugins' );
    }

    Imagine when the third plugin has to update something and wants to clear the cache, in this way this problem would be solved. The cache plugins are a lot, but they are not infinite. I think it would be also the interest of cache plugins authors to have a standard cache plugin.

    Posted: 1 year ago #
  2. Wouldn't you still be at the behest of a plugin hooking into wp_clear_cache_by_all_server_cache_plugins ? Because asking core to support all the hundreds of cache plugins isn't sustainable.

    Posted: 1 year ago #
  3. Jose
    Inactive

    WP core should just invite cache plugins authors to add

    add_action( 'wp_clear_cache_by_all_server_cache_plugins','cache_plugin_function_name' );

    in their code, nothing else. And plugin authors should just put that in their code.

    The invitation to the plugins authors could be sent when they submit their plugin for revision. It could even be done by a robot. When a plugin author submits his plugin for approval, a robot detects if it's a cache plugin, and if so it sends an email to the plugin author, including the instructions. I didn't think it could be difficult, but if you say it, I believe it. But imagine if you have this action hook, everybody would have a function to clear the server cache, no matter what cache plugin is active (of course if they respect this standard action). It would be really very nice. I think cache issues would be a lot less.

    Posted: 1 year ago #
  4. Alas that isn't how the plugin review system works.

    There is no robot. There's ... well. There's me and a couple other people.

    And the reality is people just ... won't. Which means the function will be useless. Unless you can make it somehow required (that is - caching won't work without it being called), it's impossible to enforce.

    Posted: 1 year ago #
  5. Many cache plugins have setting up for the purge/expired cache.
    And you can try w3 total cache,
    It can action hook to clear cache for you.

    Posted: 1 year ago #
  6. Jose
    Inactive

    Of course almost all cache plugins give you this function. This is not the point. The idea is to have a standard function to clear the cache, no matter what cache plugin is installed. If you have this function, all plugins and themes could use it in their code to programmatically clear the cache when needed.

    Posted: 1 year ago #
  7. Puja
    Member

    Thats great and what i also expect that by default logged in user should be avoided from caching when we use full site delivery with any cdn. WordPress should have by default an option to not to cache logged in users.

    Posted: 1 year ago #
  8. Thats great and what i also expect that by default logged in user should be avoided from caching when we use full site delivery with any cdn.

    WordPress doesn't have a CDN, so you would want to configure that with your CDN directly.

    As for caching, MOST services don't cache for logged in users. Again, you want to configure that with the cache service. Plugins generally have the same options.

    Keep in mind, the bottom line here is that there are HUNDREDS of different ways to cache data for any CMS, be it Drupal or WordPress or GoHugo. Because of that, servers have multiple ways of handling caching, as do plugins. Which means there isn't a 'one size fits all' solution, and thus no one-perfect-function. That's just not how it works.

    Posted: 1 year ago #
  9. johnhnmac
    Member

    I have problem while developing a theme to recheck the changes but due to cache some times I lost what actually going wring to not update it.

    Posted: 11 months ago #
  10. Apkextractor
    Member

    yeah! That's a welcoming update. By default, it will not cache for the logged users, WordPress should build an option to delete the cache of logged users and even the public cache, that would be great!

    By the way, I am using W3 Total Cache for my sites, it is good but too advanced for my level. Could you please share a tutorial on using that?

    Thanks in advance!

    Posted: 11 months ago #

RSS feed for this topic

Reply »

You must log in to post.

  • Rating

    12345
    0 Votes
  • Status

    This idea is under consideration