Tuesday, September 18, 2012

Cache

http://blogs.technet.com/b/stefan_gossner/archive/2005/07/11/407522.aspx


<asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled"></asp:TextBox>

You can disable ASP.Net output caching for the entire application by putting it in your web.config file.

<configuration>
    <system.web>
        <caching>
            <outputCache enableOutputCache="false">
            </outputCache>
        </caching>
    </system.web>
</configuration>
But unless you're actually putting anything in the cache in the first place, you don't have anything to worry about.

-------------------------------------------------
Declarative Approach:

<%@ OutputCache Duration="60" Location="Server" VaryByParam="None" %>

Programmatic Approach:

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Server);

What I found is that when using CTRL-F5 the declarative approach always returned the cached version but the programmatic approach returned a new version from the server. Not what I was looking for as I needed to control the amount of time but without affecting any other caching features.

Finally someone in the ASP.NET caching newsgroup was able to point me to the solution for this. There is an extra property that needs to be set to ensure that the cache gets persisted through CTRL-F5.

Here is now the complete code:

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetValidUntilExpires(true);

-------------------------------------------------------------------


up vote
1
down vote
accepted
you cannot clear browser cache.the only idea is declare a session variable in c# code in page load and set its value is 1 at the very first time

if (!IsPostBack)
            {
Session["refresh"]="1"
}
you will need to set session variable in image upload button event Session["refresh"]="1" then create a refresh button .in the button event do the following thats all.after completeing your upload,click on the refresh button.then it work as ctrl+f5 button.if you not set the session value 0 in refresh button event the last event is again takesplace.if you enter a value in database,the same task takesplace if you not set session variable 0.

   if(Session["refresh"].ToString()=="1")
   {
      Response.Write("<script type='text/javascript'>locaton.reload()</script>");
      Session["refresh"]="0";
    }
-----------------------------------------------------------
<asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
---------------------------------------------------------------------------------

No comments:

Post a Comment