Search code examples
wordpressapirestcachingwordpress-rest-api

Prevent / Disable cache in REST Wordpress


I would like to know if there is a way to prevent cache in wordpress inside the REST API.I have this minimal example:

add_action('rest_api_init', 'get_wp_page_fn2' );

function get_wp_page_fn2(){
    register_rest_route( '/wp/v2/tf_api/' ,'get_wp_page2', 
        array(
            'methods'  =>'GET',
            'callback' => 'get_wp_page_callback2',
        ) 
    );
}

function get_wp_page_callback2( $request) {
    $response = [
        "response" => 1,
        "url" => 33,
    ];
    echo json_encode($response);
    die(); 
}

If I change "response" => test, it takes about 5/10 minutes to update it. It's kind of a nightmare to do dev like that.

I try a lot of stuff but nothing seems to be working


Solution

  • Took me like a day. Since I'm using Mamp pro, I have to deal with this https://documentation-4.mamp.info/en/MAMP-PRO-Mac/Languages/PHP/index.html