In my ASP.NET application, I use HttpWebRequest to retrieve external resources that I would like to cache. Consider the following code:
var req = WebRequest.Create("http://google.com/"); req.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable); var resp = req.GetResponse(); Console.WriteLine(resp.IsFromCache); var answ = (new StreamReader(resp.GetResponseStream())).ReadToEnd(); Console.WriteLine(answ.Length);
HttpWebRequest uses the IE cache, so when I run it as a regular user (in a tiny cmd test application), the data is cached to %userprofile%\Local Settings\Temporary Internet Files , and the following responses are read from the cache.
I thought that when such code runs inside an ASP.NET application, the data will be cached until ...\ASPNET\Local Settings\Temporary Internet Files , but this is not the case and the cache is never used.
What am I doing wrong? How to force HttpWebRequest to use cache in ASP.NET?
piotrsz
source share