views:

279

answers:

5

Is it possible to clear all site cache? I would like to do this when the user logs out or the session expires instead of instructing the browser not to cache on each request.

Tom

+3  A: 

As far as I know, there is no way to instruct the browser to clear all the pages it has cached for your site. The only control that you, as a website author, have over caching of a page occurs when the browser tries to access that page. You can specify that cached versions of your pages should expire at a certain time using the Expires header, but even then the browser won't actually clear the page from its cache at that time.

David Zaslavsky
I figured this was the case, but was hoping there might be a way to clear it all at once. Thank you for the confirmation.
Thomas Kessler
+2  A: 

i certainly hope not - that would give the web site descructive powers over the client machine!

Steven A. Lowe
A: 

If you are talking about asp.net cache objects, you can use this:

    For Each elem As DictionaryEntry In Cache
      Cache.Remove(elem.Key)
    Next

to remove items from the cache, but that may not be the full-extent of what you are trying to accomplish.

EJB
+1  A: 

If security is your main concern here, why not use HTTPS? Browsers don't cache content received via HTTPS (or cache it only in memory).

Tsvetomir Tsonev
Not sure about that: See this question: http://stackoverflow.com/questions/174348/will-web-browsers-cache-content-over-https
VBNight
Yes, I agree that this depends on the browsers settings. The default settings in IE and Firefox prohibit caching of HTTPS content on disk.
Tsvetomir Tsonev
+1  A: 

One tricky way to mimic this would be to include the session-id as a parameter when referencing any static piece of content on the site. When the user establishes the session, the browser will recognize all the pieces of content as new due to the inclusion of this parameter. For the duration of the session the browser will used the static content in its cache. After the user logs out and logs back in again, the session-id parameter for the static contents will be different, so the browser will recognize this is as completely new content and will download everything again.

That being said... this is a hack and I wouldn't recommend pursuing it.. For what reason do you want the user's cache to be cleared after their session expires? There's probably a better solution that can fit your situation as opposed to what you are currently asking for.

Todd