Is this effective to prevent document caching?

Last post 11-12-2009 2:15 PM by g_p_k_. 4 replies.

Sort Posts:

  • Is this effective to prevent document caching?

    11-12-2009, 12:29 PM
    • Member
      2 point Member
    • g_p_k_
    • Member since 08-20-2008, 3:16 AM
    • Posts 13

    I've created a page containing a hyperlink to an excel file. I noticed that my browser would keep displaying an old copy of this file even after I refresh the page and delete temporary internet files. Using a tip I picked up in another post, I swapped the hyperlink for a button and in the button click event I append the link to the file with a timestamp(as a querystring). therefore the file seems unique to the browser everytime its opened.

    It seems to work so far; I'd just like to know if there's a more effective method of making the browser open the newest copy of the document everytime.

  • Re: Is this effective to prevent document caching?

    11-12-2009, 12:36 PM
    • Member
      586 point Member
    • ScottR27
    • Member since 02-14-2008, 3:27 PM
    • Maryland
    • Posts 104

    g_p_k,

    Add the following line in your onload event to prevent the page from caching.

    Response.Cache.SetCacheability(HttpCacheability.NoCache) 


    This will cause the page to always download the latest copy of your document.  One caveat, it will prevent the page from caching anything else.  So use with caution.

    Hope this helps,

    --Scott

  • Re: Is this effective to prevent document caching?

    11-12-2009, 1:27 PM
    • Member
      2 point Member
    • g_p_k_
    • Member since 08-20-2008, 3:16 AM
    • Posts 13

    I tried that initially before adding the button - but did not get the desired effect. browser still opened the old file.


  • Re: Is this effective to prevent document caching?

    11-12-2009, 1:56 PM
    Answer
    • Member
      586 point Member
    • ScottR27
    • Member since 02-14-2008, 3:27 PM
    • Maryland
    • Posts 104

    From this post: http://www.hotscripts.com/forums/asp/25526-solved-urgent-page-caching-issue-iis6-0-a.html

    Try adding

    Response.Cache.SetAllowResponseInBrowserHistory(false);

    Along with the above Nocache.

  • Re: Is this effective to prevent document caching?

    11-12-2009, 2:15 PM
    • Member
      2 point Member
    • g_p_k_
    • Member since 08-20-2008, 3:16 AM
    • Posts 13

    Thank you for your effort ScottR27.  So in your opinion the button approach is not an effective solution or should I use it in conjuction with what you suggest or what you suggest is enough to permanently sort out the problem?

    I will test again using what you've suggested and mark as answer if it proves to be effective.

Page 1 of 1 (5 items)