0

Under the active theme folder, I have a search-autocomplete.php file which uses various WP queries to create smart JSON results delivered via AJAX to a jQuery UI Autocomplete input field. It's not a normal template file (in fact it shouldn't really be in the theme's folder, it could be a plugin), but it loads the needed WP functions with this line:

require_once("../../../wp-load.php");

However, since it doesn't execute the normal hooks a full page executes, it will never be cached by W3TC or Super Cache, which is obviously suboptimal, especially for something that gets requested with almost every keypress on a search field.

Is there any way to manually tell W3TC via its API to cache this JSON and get it from the cache if appropriate?** Or should I go ahead and code my own caching mini-script for this kind of stuff?

  • 1
    I imagine it would be much easier if you were using the AJAX API or an endpoint for this, then you would at least be operating within the context of WordPress. – Milo Sep 19 '14 at 0:03
0

No caching plugin will cache ajax request because it is considered a bad idea to cache a post request as they are usually used to change the state of the site and therefor might have a different response.

You will have to write such a caching by yourself.

  • It's not a POST request, it's a GET request just like the normal search results page. – guidod Sep 19 '14 at 10:46
  • better questions with full details -> better answers. This gets totally off-topic as each plugin may have its own different handling of get requests and as you know plugin specific questions are off-topic. – Mark Kaplun Sep 19 '14 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.