2

I used following to cache my ASP.NET page.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));

The problem is when I send AJAX (XmlHttpRequest) request from other page to this page, that response does not get cached on any browser but IE. (On IE, it gets cached even if I don't specify). How do I make it cache? Any client side solution? Thanks in advance...

mihsathe
  • 8,904
  • 12
  • 38
  • 54
  • similar question :http://stackoverflow.com/questions/650440/cache-ajax-requests –  Dec 08 '10 at 06:58
  • You may already know this, but it is important to ensure that your request is a GET and not a POST - most browsers will not cache POST requests regardless of the headers. – Justin Dec 08 '10 at 07:28

3 Answers3

1

Refer Links :

Cache AJAX requests

http://developer.yahoo.net/blog/archives/2007/05/high_performanc_2.html
http://developer.yahoo.net/blog/archives/2007/07/high_performanc_11.html

Expiring cache :

  header("Cache-Control: private, max-age=$seconds");
  header("Expires: ".gmdate('r', time()+$seconds));

I hppe it will help you.

Community
  • 1
  • 1
  • But believe me... IE caches it even if you refresh... I've tested it with changed content... the only way through in that case is close the browser and start again... – mihsathe Dec 08 '10 at 07:03
  • Check : http://stackoverflow.com/questions/552710/how-best-to-work-with-the-expires-header-in-asp-net-mvc –  Dec 08 '10 at 07:27
0

This might not answer your question.. but I think you should do server-side caching instead of client-side caching for ajax requests.. if your botheration is performance on repeated ajax requests.. client-side caching has a lot of parameters based on the user and the browser types which is not an ideal place to depend on for caching.

Client-side cache, ideally, is for the user to set to increase his browsing performance independent of websites / web applications.

  • But how do I do it? that is what my question it. I am searching for a client side solution cause standard server side one didn't work for me. – mihsathe Dec 08 '10 at 11:32
  • For server-side caching: If you are using IIS 6 + for web server, you should be able to set 'Output caching' at iis config level itself for your web application. .. easiest approach without any code changes. –  Dec 09 '10 at 14:37
-1

you can add a dynamic querystring at the end of the url to get the unique data from ajax request each time.

so your url for ajax request could be like this:

var myUrl = "http://mysite.com/hello.aspx?timestamp=" + new Date().getTime();
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66