Title: Automatically cache a flushed cache
Last modified: May 10, 2019

---

# Automatically cache a flushed cache

 *  Resolved [euveng](https://wordpress.org/support/users/euveng/)
 * (@euveng)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/)
 * 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](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/#post-11525591)
 * Hi [@euveng](https://wordpress.org/support/users/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](https://wordpress.org/support/users/euveng/)
 * (@euveng)
 * [7 years ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/#post-11548661)
 * 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](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/#post-11550076)
 * [@euveng](https://wordpress.org/support/users/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](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/#post-11648956)
 * Hi [@euveng](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/wp-rest-cache/assets/icon-256x256.png?rev=3328849)
 * [WP REST Cache](https://wordpress.org/plugins/wp-rest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-cache/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Acato](https://wordpress.org/support/users/acato/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/automatically-cache-a-flushed-cache/#post-11648956)
 * Status: resolved