• Resolved euveng

    (@euveng)


    Hi guys thanks for the great work with the plugin.

    Is there a method available to regenerate a cache that’s just been flushed?

    My use case is like so: I have an spa that consumes the wp rest api which loads pretty quick when a cache is available. I’ve set it up such that the cache is flushed when a post is saved. Now instead of waiting for the next api call to regenerate a cache (which results in longer waiting time for the unsuspecting visitor) I would like the cache to be regenerated immediately after getting flushed, so that it’s sitting there waiting for the next api call.

    Any help on this will be greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Acato

    (@acato)

    Hi @euveng

    Thank you for using our plugin!

    At this point there is no method available for regenerating a cache that has just been flushed. We do however have plans to implement a cron job that will regenerate flushed cached on a regular time interval (starting with most requested caches first).

    Thread Starter euveng

    (@euveng)

    That’s great. Would this regeneration be on a fixed interval basis or can this be controlled in settings?

    If I were to extend your plugin with the functionality I described, which webhook would you recommend I use?

    Plugin Author Acato

    (@acato)

    @euveng It will be a setting to turn on or off the regeneration (not everyone will need it), but also a setting for the time interval.

    There isn’t really one hook you can use. Ofcourse there are some hooks we use to determine that a cache needs to be flushed ( save_post, delete_post, edited_term, … ), but this doesn’t tell you which cache is actually flushed (because we flush all related caches and this can be multiple caches if one post is edited). And while typing this I realize we probably should add some hooks ourselves which will be fired when a single cache is flushed.
    But even then that will not be enough, because the caches are stored in transients, which expire after a certain amount of time (which you can specify in the settings). When a transient expires, this happens silently and does not trigger any hook. That is why we would do it using a cron job.

    What this cron job will do is retrieve a list of caches (using \WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->get_api_data($api_type, $per_page, $page_number); ) and then for each cache which has is_active set to false regenerate the cache. So you could already implement such a cron job yourself, or wait until we have implemented it ??

    Plugin Author Acato

    (@acato)

    Hi @euveng

    We just released a new version of our plugin which includes the regeneration of expired (or flushed) caches. It is a setting which you will need to enable, otherwise no regeneration will be done.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Automatically cache a flushed cache’ is closed to new replies.