Title: can every cache have different cache timeout
Last modified: October 18, 2023

---

# can every cache have different cache timeout

 *  Resolved [superjin001](https://wordpress.org/support/users/superjin001/)
 * (@superjin001)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/can-every-cache-different-cache-timeout/)
 * Hi, thank your for your plugin, it is very helpful, because my project is highly
   customized, some rest APIs rely on external interfaces. I hope that this type
   apis has a shorter cache timeout, while other apis have a longer cache timeout.
   So may I ask if there is any method to set different cache timeouts for different
   rest APIs for our wordpress rest api. If we can make it, please let me know, 
   thank you in advance!
    -  This topic was modified 2 years, 7 months ago by [superjin001](https://wordpress.org/support/users/superjin001/).
    -  This topic was modified 2 years, 7 months ago by [superjin001](https://wordpress.org/support/users/superjin001/).

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

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/can-every-cache-different-cache-timeout/#post-17131996)
 * Hi [@superjin001](https://wordpress.org/support/users/superjin001/)
 * Thank you for using our plugin!
   Yes, you can do something like this:
 *     ```wp-block-code
       /**
        * Change the timeout for different endpoints.
        *
        * @param int $timeout The timeout as set in the settings.
        * @param array $options An array of options, containing the current uri ('uri'), the object type ('object_type'), the request headers ('request_headers') and the request method ('request_method').
        *
        * @return int
        */
       function wprc_variable_timeout( $timeout, $options ) {
       	if ( false !== strpos( 'wp/v2/posts', $options['uri'] ) ) {
       		$timeout = DAY_IN_SECONDS;
       	}
   
       	return $timeout;
       }
   
       add_filter( 'wp_rest_cache/timeout', 'wprc_variable_timeout', 10, 2 );
       ```
   
 *  Thread Starter [superjin001](https://wordpress.org/support/users/superjin001/)
 * (@superjin001)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/can-every-cache-different-cache-timeout/#post-17134973)
 * Hi @[Richard Korthuis](https://wordpress.org/support/users/rockfire/) , thank
   you for your quick reply, I tried the way you told, and it works, I didn’t expect
   a free plugin can be made so good and support quick Q&A, thank you again!
 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/can-every-cache-different-cache-timeout/#post-17135122)
 * Hi [@superjin001](https://wordpress.org/support/users/superjin001/),
   Good to 
   hear it works for you! I must admit I am not always this quick in answering. 
   You just happened to have send your question just before I opened my email and
   had time to respond 😛 If you have any more questions, feel free to open a new
   topic!

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

The topic ‘can every cache have different cache timeout’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/can-every-cache-different-cache-timeout/#post-17135122)
 * Status: resolved