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: 2 weeks ago #
  2. Ipstenu (Mika Epstein)
    Lead Plugin Wrangler

    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: 2 weeks 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: 2 weeks ago #
  4. Ipstenu (Mika Epstein)
    Lead Plugin Wrangler

    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: 2 weeks 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: 2 weeks 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: 2 weeks 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 week ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    0 Votes
  • Status

    This idea is under consideration