• Resolved tiborudvari

    (@tiborudvari)


    I want to setup a REST endpoint to purge everything.

    I’m trying this inside of functions.php, but it does not seem to work.
    It does seem to get something because after I login to the backend it seems to have cleared it, but not before.

    
    ...
    register_rest_route( 'ppt/v1', '/purge', array(
      'methods' => 'GET',
      'callback' => 'purge_cache',
    	  ));
    });
    
    function purge_cache(){
      do_action('litespeed_purge_all');
      return array('status' => 'success');
    }

    I saw in other threads that something like wp-load.php was imported, could that be related to the issue?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    function my_purge() {
    do_action( 'litespeed_purge_all' );
    return array('status' => 'success');
    }
    
    add_action( 'rest_api_init', function () {
      register_rest_route( 'purge/v1', '/purge_all', array(
        'methods' => 'GET',
        'callback' => 'my_purge',
      ) );
    } );

    goes to theme’s funcitons.php

    then by https://domain.com/?rest_route=/purge/v1/purge_all

    tested and confirmed working on my site

    just make sure you did NOT cache the WP REST , otherwise only first access will call to purge , afterwards, since it is cached, it won’t trigger the purge

    Best regards,

    Thread Starter tiborudvari

    (@tiborudvari)

    Oh yes, I fell into a little bit of circular logic. I want to cache my REST API’s, since I’m using it quite extensively via React. Is there a way not to cache that route in particular?

    Thread Starter tiborudvari

    (@tiborudvari)

    I excluded my purge API route in the settings and now it works fine, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘litespeed_purge_all with REST API’ is closed to new replies.