通常我在nginx config规则中不允许caching所有的XMLHttpRequest:
map $http_x_requested_with $nocache_01 { default 0; XMLHttpRequest 1; }
有没有办法caching只有GET Ajax请求?
没有显示,但是假设在configuration中有一个if块,如下所示:
if ($nocache_01) { ... }
相反,通过连接这个variables和请求方法,更明确的检查是可能的,即:
if ($nocache_01$request_method = "1GET") { ... }
或者,例如,根本不使用地图:
if ($http_x_requested_with$request_method = "XMLHttpRequestGET") { ... }
感谢AD7six提示。 现在,我的地图看起来像。
map $http_x_requested_with$request_method $nocache_01 { default 0; XMLHttpRequestGET 0; ~XMLHttpRequest(PUT|PATH|DELETE|POST) 1; }
这意味着XMLHttpRequest(PUT | PATH | DELETE | POST)不会被caching
fastcgi_no_cache $nocache_01; fastcgi_cache_bypass $nocache_01;