Problem with Cache plugin & REST API
-
Hello.
Thanks for creating a great plugin…
I’m having a problem with the Cache Plugin, have been trying for hours but still don’t understand what’s going on.
I switch from WP Rocket to Super Page Cache for Cloudflare Plugin.
I use rest_api to update the “View” Meta for the post every time a User visits. The code is as follows:
function updatePostViewApi(WP_REST_Request $request) { $postID = $request['id']; $postType = get_post_type($postID); if (is_null($postType)) { return new WP_REST_Response(null, 404); } setPostView($postID, $postType); return new WP_REST_Response(null, 200); } add_action('rest_api_init', function () { register_rest_route('catalog', '/post_view_data1/(?P<id>\d+)', array( 'methods' => 'GET', 'callback'=> 'updatePostViewApi', 'args' => array( 'id' => array( 'validate_callback' => function ($param, $request, $key) { return is_numeric($param); }, ), ), )); register_rest_route('catalog', '/post_view_data2/(?P<id>\d+)', array( 'methods' => 'GET', 'callback' => 'updatePostViewApi', 'args' => array( 'id' => array( 'validate_callback' => function ($param, $request, $key) { return is_numeric($param); }, ), ), )); register_rest_route('catalog', '/post_view_data3/(?P<id>\d+)', array( 'methods' => 'GET', 'callback' => 'updatePostViewApi', 'args' => array( 'id' => array( 'validate_callback' => function ($param, $request, $key) { return is_numeric($param); }, ), ), )); });Then I use extra code to generate Shortcode and use Plugin: Content No Cache to load Meta via Ajax it works perfectly with WP Rocket.
However with the Super Page Cache for Cloudflare Plugin. Code only updates 1 time if CACHE Status is not HIT.
Looks like Cloudflare is caching rest_api and preventing it from working once Cache Status is HIT. Or am I missing an installation?
Thanks if you have any advice on how to fix this problem.
The topic ‘Problem with Cache plugin & REST API’ is closed to new replies.