Click here to Skip to main content
15,867,991 members
Please Sign up or sign in to vote.
4.20/5 (3 votes)
Hi All,
i am developing an web application when i tested it on Safari browser in IOS 6 version.On every request its fetching same cache results .
Is it a browser problem.If it not help me in clearing the cache in java script/J query.

Thanks in advance
Posted

Have you explicitly set cache to false in ajax call?

JavaScript
$.ajax({
  url: "test.html",
  cache: false,
  success: function(data){
    //some processing
  }
});




http://api.jquery.com/jQuery.ajax/[^]
 
Share this answer
 
Comments
Tharaka MTR 16-Jan-13 2:28am    
I tried this, but it didn't work for me.
Vyacheslav Voronenko 16-Jan-13 2:35am    
Ooops! I missed that it is IOS6! Apple ignores the rules, and uses it's own caching policy. Common workaround, is to add some fake unique parameter to query (for example current date and time).

Proof:
http://arstechnica.com/apple/2012/09/developers-claim-safari-in-ios-6-breaks-web-apps-with-aggressive-caching/

Another option, like correctly mentioned A Patra - set to no-cache:

No Cache-Control or Expires headers = iOS6 Safari will cache
Cache-Control max-age=0 and an immediate Expires = iOS6 Safari will cache
Cache-Control: no-cache = iOS6 Safari will NOT cache

Tharaka MTR 16-Jan-13 2:38am    
Yep.
ravithejag 16-Jan-13 5:33am    
thanks Vyacheslav
It happens when you make a httpget request.actually by default cache is set to true .you need to use some attribute like:
apply this attribute to your controller or action

C#
[OutputCache(Duration=0,NoStore=true)]


here the cache duration is set to 0 and nostore property says that cached data will not be stored at client side.
 
Share this answer
 
You can also set the following parameters in your asp.net page so that it will not get cached in the client browser

Response.Buffer = True
Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0))
Response.Expires = 0
Response.CacheControl = "no-cache"

:)
 
Share this answer
 
This is exactly iOS6 breaking change.

Safari on iOS6 will cache POSTs that have either no Cache-Control headers or even "Cache-Control: max-age=0".

I also experienced with this issue and fix as follows.
In your web service method, please add the following line
C#
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

ex:
C#
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void HelloWorld()
{
	HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

}



if you need any more information please check in following thread.
http://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results[^]
 
Share this answer
 
Comments
ravithejag 16-Jan-13 3:38am    
Thanks Tharaka
Tharaka MTR 16-Jan-13 4:09am    
if you get the answer, it is best practice to mark as answer. then thread will be closed.
use these tags in Page

XML
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900