Title: Manually flush cache
Last modified: March 26, 2019

---

# Manually flush cache

 *  Resolved [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/)
 * Hey,
 * I am using only custom endpoints.
 * Is there any way to flush the cache manually?
 * Best,
    Adam

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

 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11355942)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * Yes, there are multiple ways of manually clearing the cache:
    - Clear all caches, by clicking the ‘Clear REST Cache’ button in the wp-admin
      bar (top of your screen)
    - Clearing a selection of caches, by going to Settings > WP REST Cache > Endpoint
      API Caches, select one or more caches and then Bulk Actions > Flush Cache 
      > Apply
    - Clearing one single cache, by going to Settings > WP REST Cache > Endpoint
      API Caches, hover over the cache you want to flush and click ‘Flush Cache’
 * I hop this answers your question.
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11359706)
 * Hey [@acato](https://wordpress.org/support/users/acato/)
 * Is there any way to do this programatically?
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11361045)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * At this point there are only two functions available for programatically flushing
   caches:
 * **1. Flush all caches of a specific object type**
    Example: `\WP_Rest_Cache_Plugin\
   Includes\Caching\Caching::get_instance()->delete_object_type_caches( 'products');`
   This deletes all caches for object type `products`
 * **2. Flush a specific cache**
    Example: `\WP_Rest_Cache_Plugin\Includes\Caching\
   Caching::get_instance()->delete_cache( '8dbc9f7badb0ed2d50f1eaf200422a49' );`
   Unfortunately as you can see, you would need the cache key for that. Which by
   the way is simply a md5 hash of the endpoint path with query parameters. So for`
   https://www.domain.com/wp-json/wp/v2/pages` the cache key would be `md5( '/wp-
   json/wp/v2/pages' );`. However keep in mind that any query parameters should 
   be ksort’ed.
 * Your question makes me however realize that we should add more (better usable)
   functions for flushing caches programatically. I will discuss this internally
   and add some functions in the near future.
    Do you have any suggestions on how
   you would like to do this? I.e. flushing all caches for a specific endpoint regardless
   of the query parameters, flushing a cache by it’s specific path (without the 
   need to hash it yourself), … ?
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11364746)
 * Okay cool I can use those functions that’s great. Converting the endpoint path
   to md5 isn’t a problem seems to be matching here from a quick test.
 * Those use cases you describe is basically what i’m looking to achieve.
 * – Flushing all caches for an endpoint regardless of query params
    – Flushing 
   cache by specific path/endpoint
 * Would be a good place to start.
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11365535)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * I will add it to my todo-list. Unfortunately I don’t have any time left to work
   on it this week.
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11381522)
 * No problem, the information you’ve provided is plenty for my solution.
 * I have some endpoints that check authentication inside them, I would like a way
   to make sure any authenticated requests by admins are not cached. Any ideas on
   how to approach this?
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11382162)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * We just released a new version of our plugin which now includes a function to
   programatically flush caches by endpoint. So for instance if you want to flush
   the caches for the endpoint `/wp-json/wp/v2/pages` you can do so like this:
    `\
   WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_cache_by_endpoint('/
   wp-json/wp/v2/pages' );`
 * This function accepts two extra parameters:
    1. `$strictness`: This defines how
   strict you want the caches to match, you have three options for this: `\WP_Rest_Cache_Plugin\
   Includes\Caching\Caching::FLUSH_STRICT`: Delete caches by an endpoint path matching
   only this exact same endpoint path (and query params). `\WP_Rest_Cache_Plugin\
   Includes\Caching\Caching::FLUSH_PARAMS`: Delete caches by an endpoint path matching
   the exact same endpoint path with any query params that might have been used.`\
   WP_Rest_Cache_Plugin\Includes\Caching\Caching::FLUSH_LOOSE`: Delete caches by
   an endpoint path matching any cache that was called starting with the endpoint
   path (ignoring any query params or subpaths following the given path).
 * 2. `$force`: Should the caches be deleted ($force = true) or just flushed ($force
   = false).
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11382185)
 * About your endpoint that checks authentication inside them: are you sure you 
   actually want this endpoint to be cached?
 * At this point I don’t really see an option to do this, the code where we check
   if we should cache or not (`\includes\api\class-endpoint-api.php` line 203) is
   executed from a must use plugin and therefore is executed before any plugin or
   theme code. So adding a filter there will not help you very much since the `apply_filters`
   is than executed before you added your filter.
    I am going to think about a solution
   for this and discuss it internally, maybe we can find a solution that works for
   you.
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11401851)
 * Thanks for the update! It works great, definitely fixed the issue I was having
   before with detecting object type and throwing an error.
 * I think I want to cache the endpoint, this is my use case:
 * I have a product catalogue that is cached. Admin users can see ‘draft’ and ‘private’
   status products, whereas Customers can only see ‘publish’ products. So the cached
   responses won’t actually return what an admin should see, and if an admin sets
   the cached response then it will show ‘draft’ and ‘private’ products to customers.
 * I guess I could create an endpoint specifically for admin users to access the
   catalogue.
 * Let me know your thoughts.
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11402740)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * Well creating a new (duplicate) endpoint doesn’t feel right.
 * After some consideration I think there are two possible solutions to this problem:
 * 1. We add a check to see if the current user is authenticated and if so, do not
   use caching. But that would mean that all responses for authenticated users are
   no longer using caching. That doesn’t feel right either.
 * 2. We can implement the option for you to use an extra parameter to tell the 
   WP REST Cache plugin to skip caching. That way you can decide for each request
   if you want to use caching or not. So for admin users you would add an extra 
   parameter to the REST call. Does that sound like an option to you?
 *  Thread Starter [botoxparty](https://wordpress.org/support/users/adamhammad/)
 * (@adamhammad)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11419592)
 * Sorry thought I replied to this.
 * [@acato](https://wordpress.org/support/users/acato/)
 * Number 2 sounds like a more flexible option, I can see this being used for more
   than just authentication purposes. e.g. Do not cache based on an environment 
   variable.
 *  Plugin Author [Acato](https://wordpress.org/support/users/acato/)
 * (@acato)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11428488)
 * Hi [@adamhammad](https://wordpress.org/support/users/adamhammad/)
 * We have just released a new verion of the plugin. We have added a GET-parameter
   you can use to skip caching. Simply add `?skip_cache=1` to you REST call.
 * Please let us know if this works for you!
 *  [tuomo2](https://wordpress.org/support/users/tuomo2/)
 * (@tuomo2)
 * [6 years, 12 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11587012)
 * EDIT: Nevermind, will get back to you when I’ve investigated a little bit more
   🙂 Thank you for an awesome plugin!

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

The topic ‘Manually flush 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/)

 * 13 replies
 * 3 participants
 * Last reply from: [tuomo2](https://wordpress.org/support/users/tuomo2/)
 * Last activity: [6 years, 12 months ago](https://wordpress.org/support/topic/manually-flush-cache/#post-11587012)
 * Status: resolved