openresty / srcache-nginx-module

Transparent subrequest-based caching layout for arbitrary nginx locations.
http://wiki.nginx.org/NginxHttpSRCacheModule
474 stars 103 forks source link

Conflict with multiple currency plugin #80

Closed duylddev closed 5 years ago

duylddev commented 5 years ago

Our Wordpress website has a mutilple currency plugin and here's the thing

With the same url like: https://example.com/products/product-name The plugin basiclly check user Geolocation and return the match currency, but SRCache return the HTML content before the plugin run so US or AU or UK user see the US price That's not true

What should I do now?

kapouer commented 5 years ago

Your website varies the response using the request IP. That setup doesn't go well with a cache in the proxy. The right way to do this is to map the request IP to a request Header before srcache handles the request, and Vary the response upon that header.

kapouer commented 5 years ago

I wrote Actual detected country because the Country detected by geoip might not be the one you actually choose in the application. For example you might map 'FR' and 'ES' to 'EU' in the application, so you have to tell the cache (as done above) to set its store key accordingly.

duylddev commented 5 years ago

Thank you for replying, I understand that solution but I don't know how to build store key using response X-ClientCountry header.

Could you give more information?

duylddev commented 5 years ago

It's great if you give me an example

kapouer commented 5 years ago

From the documentation example (assuming you're using X-Client-Country header)

  more_set_headers 'X-Country-Code: $geoip_city_country_code3';
  set $fetchKey "$geoip_city_country_code3-$uri?$args";
  set $storeKey "$sent_http_x_client_country-$uri?$args";
  srcache_fetch GET /memc $fetchKey;
  srcache_store PUT /memc $storeKey;

Cool huh ?!?

duylddev commented 5 years ago

set $key "example.com_page:https$http_cf_ipcountry$request_method$host$request_uri";

I'm using Cloudflare so that's my config and it's worked =))))

Thank you so much :D

kapouer commented 5 years ago

Cool ! If you're using Cloudflare then yes, there is already a http header available, so indeed there is no need to set one up. You might want to close this issue...

duylddev commented 5 years ago

Oh, I forgot it too much focus on coding =))