Title: Cache doesn&#8217;t work
Last modified: June 9, 2022

---

# Cache doesn’t work

 *  Resolved [m777](https://wordpress.org/support/users/m777/)
 * (@m777)
 * [4 years ago](https://wordpress.org/support/topic/cache-doesnt-work-3/)
 * Hello
    I’ve tried a lot of times this plugin with custom methods and added function
   below but cache doesn’t works anyway.(
 *     ```
       add_action( 'rest_api_init', function () {
           register_rest_route( 'places', 'all', array(
               'methods' => 'GET',
               'callback' => 'api_get_places_all',
           ) );
       } );
       ```
   
 * and tried with version define like this:
 *     ```
       add_action( 'rest_api_init', function () {
           register_rest_route( 'v1/places', 'all', array(
               'methods' => 'GET',
               'callback' => 'api_get_places_all',
           ) );
       } );
       ```
   
 * ——
 *     ```
       function wprc_add_places_list_endpoint( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'places' ] ) || ! in_array( 'all', $allowed_endpoints[ 'places' ] ) ) {
               $allowed_endpoints[ 'places' ][] = 'all';
           }
           return $allowed_endpoints;
       }
   
       add_action( 'wp_rest_cache/allowed_endpoints', 'wprc_add_places_list_endpoint', 10, 1);
       ```
   
 * Maybe plugin require any server settings for normal functionality?
    -  This topic was modified 4 years ago by [m777](https://wordpress.org/support/users/m777/).
    -  This topic was modified 4 years ago by [m777](https://wordpress.org/support/users/m777/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcache-doesnt-work-3%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/cache-doesnt-work-3/#post-15818213)
 * Hi [@m777](https://wordpress.org/support/users/m777/)
 * Sorry for the late reply.
 * I don’t see anything wrong with your code. But just to be sure I recreated it
   on my local environment and this is working code:
 *     ```
       add_action( 'rest_api_init', function () {
       	register_rest_route( 'places/v1', 'all', array(
       		'methods' => 'GET',
       		'callback' => 'api_get_places_all',
       	) );
       } );
   
       function wprc_add_places_list_endpoint( $allowed_endpoints ) {
       	if ( ! isset( $allowed_endpoints[ 'places/v1' ] ) || ! in_array( 'all', $allowed_endpoints[ 'places/v1' ] ) ) {
       		$allowed_endpoints[ 'places/v1' ][] = 'all';
       	}
       	return $allowed_endpoints;
       }
   
       add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_places_list_endpoint', 10, 1);
       ```
   
 * So calls to [https://<yourwebsite>/wp-json/places/v1/all](https://<yourwebsite>/wp-json/places/v1/all)
   should now be cached.
 * Please keep in mind that the first time you call the endpoint it might not be
   cached right away, but after a second call it should be cached (this has to do
   with the technical setup of the caching and the filters).

Viewing 1 replies (of 1 total)

The topic ‘Cache doesn’t work’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/cache-doesnt-work-3/#post-15818213)
 * Status: resolved