We are writing a geolocation plugin which uses the MaxMind.com Web Service API to get location data about a user based on their IP address (Country, State/Province, City, Zip/Postal Code, etc.).
We want to display this same information to the user when they visit our site (running on WP Multisite w/ Subdomains + Domain Mapping, powered by EasyEngine)
Our code uses the built-in wp_remote_get() function to request data from Maxmind.com, and then saves the data in a cookie in the user’s browser.
We are then using simple WordPress shortcodes like [country] or [state] or [city] to display the information to the user as desired.
If the user is in California, the [state] shortcode should return “California”.
If the user is in New York, the [state] shortcode should return “New York”.
THE PROBLEM: CACHING
Our problem is that the entire page is being cached by NGINX, including the request, the cookie, etc. Users are not seeing dynamic data about themselves. Instead, they are seeing cached data from a prior user.
Several times now, I have visited the site and seen information that was totally different than mine.
I deactivated the W3TC plugin, so the only caching mechanism left is the Fastcgi_cache that EasyEngine implements.
POSSIBLE SOLUTIONS (AND CHALLENGES)
-
Disable Fastcgi_cache - which is not good if the site begins to get a lot of traffic.
-
Modify NGINX config to skip cache based on a certain rule - which is difficult because I cannot come up with a valid rule.
-
Use JavaScript/AJAX to dynamically replace the shortcodes on the page, and do not use built-in WordPress do_shortcode() function.
Can you provide some insights here as to the recommended method to move forward?