It seems that HttpWebRequest caching in WP7 is enabled by default, how do I turn it off? Adding a random param url + \"?param=\" + RND.Next(10000) works, but it\'s quite
Adding random number is not bad and it will work. I have used Time (in ajax call). Was placed in the url like a folder.
In case of HttpClient (Portable for Windows Phone) "Cache-Control": "no-cache" on server side works only sometimes. And I cannot add query string random value to RESTful api call as well.
Solution from @frno works good and looks like for HttpClient:
client.DefaultRequestHeaders.IfModifiedSince = DateTime.UtcNow;
Thank you.
How do you know it's the phone, not the server (or a proxy somewhere between) which is caching?
Have you checked this with Fiddler2 (or equivalent)?
Have you tried setting headers to disable caching?
Something like:
myRequest = (HttpWebRequest)WebRequest.Create(myUri);
myRequest.Headers["Cache-Control"] = "no-cache";
myRequest.Headers["Pragma"] = "no-cache";
I found 3 ways
string uri = "http://host.com/path?cache="+Guid.NewGuid().ToString();
var __request = (HttpWebRequest)WebRequest.Create(url.ToString()); if (__request.Headers == null) __request.Headers = new WebHeaderCollection(); __request.Headers.Add("Cache-Control", "no-cache");
[AspNetCacheProfile("GetContent")] public ResultABC GetContent(string abc) { __request = (HttpWebRequest)WebRequest.Create(abc); return __request; }
And update your web.config
<system.web> <caching> <outputCache enableOutputCache="true" /> <outputCacheSettings> <outputCacheProfiles > <add name="GetContent" duration="0" noStore="true" location="Client" varyByParam="" enabled="true"/> </outputCacheProfiles> </outputCacheSettings> </caching> ... </system.web>
We've seen the same behaviour with Silverlight hosted in Chrome.
We add a "?nocache=" + DateTime.Now.Ticks.ToString() to our request URLs if we want to prevent caching.
Yes is possible... :) I spend one week of Experiment and the answer is really simple :
HttpWebRequest _webRequest = WebRequest.CreateHttp(_currentUrl);
_webRequest.AllowReadStreamBuffering = false
_webRequest.BeginGetResponse(_onDownload,
userState);