Title: Hook for when cache is cleared
Last modified: August 26, 2022

---

# Hook for when cache is cleared

 *  Resolved [bezbeli](https://wordpress.org/support/users/bezbeli/)
 * (@bezbeli)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-for-when-cache-is-cleared/)
 * Hi, did you ever add hook for when cache is cleared, would be good to have it
   so it can trigger a url to redeploy site or clear cache ie. for headless or static
   site. I imagine simplest case would be to fire when Clear REST cache button is
   clicked.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-for-when-cache-is-cleared/#post-15991656)
 * Hi [@bezbeli](https://wordpress.org/support/users/bezbeli/)
 * Thank you for using our plugin!
 * There are several cases in which a cache record could be cleared, clicking the
   Clear REST cache button is only one of them:
    - When a users clicks the Clear REST cache button, in this case ALL caches are
      cleared
    - When a new post/term is added, in this case all overview endpoints of this
      post type/taxonomy are cleared
    - When a post/term is edited, in this case all caches that have this post/term
      in it are cleared
    - When a post/term is deleted, in this case all caches that have this post/term
      in it are cleared
    - …
    - When a cache record is expired
 * Specifically this last case makes it hard to have a reliable hook for when a 
   cache is cleared. Since we use the transient API, we have no way of detecting
   if/when a cache record expires. Furthermore, since there are several case in 
   which only a part of the cache records are cleared, how would you want to handle
   this? Triggering a hook for each seperate cache record isn’t something we are
   very happy to do, since this would influence performance when adding/editing/
   deleting a post/term.
 * So if you are looking for a hook whenever the Clear REST cache button is clicked,
   that is something we could add. That is however as said not the only case in 
   which caches are cleared and for the other cases it is a bit harder to have a
   good hook.

Viewing 1 replies (of 1 total)

The topic ‘Hook for when cache is cleared’ 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/)

## Tags

 * [hook](https://wordpress.org/support/topic-tag/hook/)

 * 1 reply
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/hook-for-when-cache-is-cleared/#post-15991656)
 * Status: resolved