CacheDuration attribute and runtime cache behaviour in asmx service

Discussion created by VKamakodu on Oct 13, 2010
Latest reply on Oct 19, 2010 by hanyong

Recently I had to cache some data in my asmx service. I used the cacheduration attribute (example here with 60 sec cache) which seems to work well in firefox but not IE. You can run the code yourself to see how it works in both browsers:

[WebMethod(CacheDuration = 60)]
public string GetCacheEntryTime(string Name)
 StringBuilder sb = new StringBuilder("Hi ");
 sb.Append(", the Cache entry was made at ");
 return (sb.ToString());

If you run IE, everytime you invoke (put the same name few times), you would see a different time stamp on every invokation. That means it's not caching. But on firefix all is well. You would see the same time stamp. The other strange behaviour is that once firefox is run, IE works as well. That's because the data is cached by the firefox already and now IE loads from that cache.


So I had to go back to using the cache object programatically and it works well both on IE and firefox. BTW, you need to use System.Web.HttpRuntime.Cache not System.Web.Caching.


Has anyone else come across this anomaly with CacheAttribute and knows why?