Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter emmanueldch

    (@emmanueldch)

    Hi, tha,ks for your answer.

    To answer your question, let me tell you, my custom /tree route is … HEAVY unfortunately.
    With the cache system of your plugin I have good results in terms of execution time when calling externally. But with a WP_Rest_Request call I have crappy results (~4.5s).


    Measurements were done like this (on localhost) :

    public static function tree()
        {
            // Starting clock time in seconds
            $start_time = microtime(true);
            $a = 1;
    
            // Start loop
            for ($i = 1; $i <= 1000; $i++) {
                $a++;
            }
    
            echo " Execution time of script = " . $execution_time . " sec";
            $request = new WP_REST_Request('GET', '/myNamespace/v1/tree');
            $response = rest_do_request($request);
            $server = rest_get_server();
            $data = $server->response_to_data($response, false);
    
            // End clock time in seconds
            $end_time = microtime(true);
    
            var_dump(($end_time - $start_time));
            die();
    
            return $data['response'];
        }

    I also measured (in the same function) a random call to /wp/v2/pages and I obtained similar results as yours.

    That’s why I wanted to see if your plugin offered cache even with internal calls.


    If so, I would also have made a “fake” call right after the line were I flush my /tree cache to ALWAYS have that route cached.

    add_filter('acf/save_post', function () {
        // Systematically flush /tree route since this route is retrieving every pages of the website
        Caching::get_instance()->delete_cache_by_endpoint('/wp-json/easyfichiers/v1/tree', Caching::FLUSH_LOOSE);
    
    // fake call right here <<<<<
    
    [...]
    
    }, 10);

    Do you have any workaround to offer ?

Viewing 1 replies (of 1 total)