Title: Programmatically flush and regenerate cache
Last modified: March 28, 2020

---

# Programmatically flush and regenerate cache

 *  Resolved [brnteka](https://wordpress.org/support/users/brnteka/)
 * (@brnteka)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/programmatically-flush-and-regenerate-cache/)
 * Thank you for the plugin, but i have a question, is it possible to programmatically
   flush all cache of a specific post type and then regenerate it? I have a cron
   job that runs once a day and updates all posts of custom type, and after its 
   done all the cache should be flushed and regenerated with the new posts data.
   Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/programmatically-flush-and-regenerate-cache/#post-12600807)
 * Hi [@brnteka](https://wordpress.org/support/users/brnteka/)
 * Thank you for using our plugin!
 * You are actually asking two different things (flushing and regenerating), so 
   I am going to answer them seperately.
 * Yes it is possible to flush all caches of a specific post type programmatically.
   For instance if you would like to flush all caches of a post type `products` 
   you can do so like this:
    `\WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()-
   >delete_object_type_caches( 'products' );` But I must say: why would that be 
   needed? If you update the post using WordPress core function the caches should
   be flushed automatically. Isn’t this the case in your situation? Or are you updating
   the posts with a direct database query?
 * About regenerating: we don’t have the option to regenerate specific post type
   caches, but we do have the option to automatically regenerate flushed (or expired)
   caches. [See our FAQ on how to set this up](https://wordpress.org/plugins/wp-rest-cache/#can%20expired%20caches%20be%20automatically%20regenerated%3F).
 *  Thread Starter [brnteka](https://wordpress.org/support/users/brnteka/)
 * (@brnteka)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/programmatically-flush-and-regenerate-cache/#post-12601132)
 * > But I must say: why would that be needed? If you update the post using WordPress
   > core function the caches should be flushed automatically. Isn’t this the case
   > in your situation? Or are you updating the posts with a direct database query?
 * I’m using Carbon Fields so this might be the case, but i call wp_update_post 
   function as well, and fields updated with CF API doesn’t seems to be flushed.
 * > About regenerating: we don’t have the option to regenerate specific post type
   > caches, but we do have the option to automatically regenerate flushed (or expired)
   > caches. See our FAQ on how to set this up.
 * If selected “once a day” what time it would be exactly? Would be great if i could
   set the time to be somewhere near after the end of a cron job.
 * Thank you for the quick response

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Programmatically flush and regenerate 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [brnteka](https://wordpress.org/support/users/brnteka/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/programmatically-flush-and-regenerate-cache/#post-12601132)
 * Status: resolved