After a bit of investigation, turns out that Safari on iOS6 will cache POSTs that have either no Cache-Control headers or even "Cache-Control: max-age=0".
(经过一番调查,结果发现iOS6上的Safari将缓存没有Cache-Control标头甚至没有“ Cache-Control:max-age = 0”的POST。)
The only way I've found of preventing this caching from happening at a global level rather than having to hack random querystrings onto the end of service calls is to set "Cache-Control: no-cache".
(我发现防止这种缓存在全局级别发生而不必将随机查询字符串砍入服务调用末尾的唯一方法是设置“ Cache-Control:no-cache”。)
So:
(所以:)
- No Cache-Control or Expires headers = iOS6 Safari will cache
(没有Cache-Control或Expires标头= iOS6 Safari将缓存)
- Cache-Control max-age=0 and an immediate Expires = iOS6 Safari will cache
(缓存控制max-age = 0,并且立即到期= iOS6 Safari将会缓存)
- Cache-Control: no-cache = iOS6 Safari will NOT cache
(缓存控制:无缓存= iOS6 Safari无法缓存)
I suspect that Apple is taking advantage of this from the HTTP spec in section 9.5 about POST:
(我怀疑Apple从9.5节有关POST的HTTP规范中利用了这一点:)
Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields.
(除非响应包含适当的Cache-Control或Expires标头字段,否则对此方法的响应不可缓存。)
However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.(但是,303(请参阅其他)响应可用于指导用户代理检索可缓存的资源。)
So in theory you can cache POST responses...who knew.
(因此,从理论上讲,您可以缓存POST响应...谁知道。)
But no other browser maker has ever thought it would be a good idea until now.(但是到目前为止,没有其他浏览器制造商曾认为这是一个好主意。)
But that does NOT account for the caching when no Cache-Control or Expires headers are set, only when there are some set.(但是,仅当设置了Cache-Control或Expires头时,才考虑缓存。)
So it must be a bug.(因此,这一定是一个错误。)
Below is what I use in the right bit of my Apache config to target the whole of my API because as it happens I don't actually want to cache anything, even gets.
(以下是在我的Apache配置的正确位置使用的全部我的API,因为发生这种情况时,我实际上并不想缓存任何东西,甚至不需要缓存任何东西。)
What I don't know is how to set this just for POSTs.(我不知道如何仅针对POST设置它。)
Header set Cache-Control "no-cache"
Update: Just noticed that I didn't point out that it is only when the POST is the same, so change any of the POST data or URL and you're fine.
(更新:只是注意到我没有指出它只是在POST相同的情况下,因此更改任何POST数据或URL都可以。)
So you can as mentioned elsewhere just add some random data to the URL or a bit of POST data.(因此,您可以像在其他地方提到的那样,仅向URL中添加一些随机数据或一些POST数据。)
Update: You can limit the "no-cache" just to POSTs if you wish like this in Apache:
(更新:如果您希望在Apache中这样,可以将“无缓存”仅限制为POST:)
SetEnvIf Request_Method "POST" IS_POST
Header set Cache-Control "no-cache" env=IS_POST