views:

137

answers:

2

Hello there,

I've got, what I would consider, a simple test web site. A single page with a single button.

Here is a copy of the source I'm working with if you would like to download it and play with it.

When that button is clicked, it creates a JavaScript timer that executes once a second. When the timer function is executed, An AJAX call is made to retrieve a text value. That text value is then placed into the DOM.

What's my problem?

IE Caching.

Crack open Task Manager and watch what happens to the iexplorer.exe process (IE 8.0.7600.16385 for me) while the timer in that page is executing.

See the memory and handle count getting larger?

alt text

Why is that happening when, by all accounts, I have caching turned off. I've got the jQuery cache option set to false in $.ajaxSetup. I've got the CacheControl header set to no-cache and no-store. The Expires header is set to DateTime.Now.AddDays(-1). The headers are set in both the page code-behind as well as the HTTP Handler's response.

Anybody got any ideas as to how I could prevent IE from caching the results of the AJAX call?

Here is what the iexplorer.exe process looks like in ProcessMonitor. I believe that the activity shown in this picture is exactly what I'm attempting to prevent.

alt text

+1  A: 

When you tell the browser not to cache the object, you're not saying "don't save this to disk", you're saying "do whatever, but don't use it again." The handles number you see is file handles, just because it's not being used for cache doesn't mean a file wasn't written and a handle to go along with it.

What you're telling IE is when you ask for that url again, that file you saved isn't a valid result for it...so go get it again, but that doesn't have anything to do with it being saved the first time.

The only issue you're seeing is IE not letting go of those file handles quickly...well that's IE, I can't explain the inner workings there. Perhaps someone else can shed some light?

Nick Craver
I see. That makes sense. I would definitely appreciate anybody with some internal knowledge about how IE works shout out a hint as to how to release unused memory/file handles (if that's even possible for an ajax application).... or is the "refresh" button the only recourse?
Joshua Hayworth
+1  A: 

Can't really shed any light on the internals of IE, or the growing memory and handle count, but a potential quick and dirty fix would be to put in a varying parameter to the ajax call, maybe based on your timer, or ticks from the current time.

Something along the lines of ...handler.axd?foo=varying_value_here

HTH

seanb
IE's behavior is reasonable in this case. What if the page referenced the same image 10 times? Would you want it loaded 10 times, even if caching was off? Add a querystring parameter to bypass the cache as sean suggests.
Frank Schwieterman
Yep! This is one of the things I'm doing as well. If you download the source code, check out a file called example.js file under a function called testFunction(). This is the function making the actual ajax call I'm talking about. I append a variable called requestNumber (an incremented integer) to the url parameter of the $.ajax call. Bottom line: it doesn't appear to make a difference.
Joshua Hayworth
Hmm - that's strange that it's not making a difference, sounds like some debugging fun and frustration to be had. Sorry that not working - usually does for me.
seanb