“_locale” parmater prevents caching
-
Hello guys,
first of all: Great plugin! Many thanks for your effort.
Unfortunately, I encountered a problem that prevents me from using the plugin. I went through the entire FAQs and also searched the support forum for a solution, but I couldn’t find a solution. I hope you can help me.
I have an endpoint (hmm/v1/overview) that I would like to have cached. I took your sample code from the FAQ and modified it accordingly:
function hmm_add_caching( $allowed_endpoints ) { $api_namespace = 'hmm/v1'; if ( ! isset( $allowed_endpoints[ $api_namespace ] ) || ! in_array( 'overview', $allowed_endpoints[ $api_namespace ] ) ) { $allowed_endpoints[ $api_namespace ][] = 'overview'; } return $allowed_endpoints; } add_filter( 'wp_rest_cache/allowed_endpoints', 'hmm_add_caching', 10, 1);
This works wonderfully as soon as you call the endpoint without parameters. ~250ms becomes only 20ms, what a dream.
I’m building a small React app for the frontend. For this I use the “apiFetch” function from “@wordpress/api-fetch”. However, this function packs a parameter at the end every time. So it turns my request into this:
“https://example.com/wp-json/hmm/v1/overview?_locale=user” instead of “https://example.com/wp-json/hmm/v1/overview”.Caching no longer works with this parameter. Did I miss something or is it a bug?
Many thanks for your help.
- The topic ‘“_locale” parmater prevents caching’ is closed to new replies.