ASP. NET page Clear Cache 1

Source: Internet
Author: User

1. Every time you open the page, you should clear the cache of this page

When the page opens, due to the presence of the cache, the newly updated data can sometimes not be refreshed on the page, which is more noticeable when the page opens as a modal window.

2.asp.net Page Cache cleanup

Asp. NET Clear Page Cache

(1) Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds (-1);
Response.Expires = 0;
Response.CacheControl = "No-cache";
Response.AddHeader ("Pragma", "No-cache");


(2) HTML method
<HEAD>
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Expires" content= "0" >
</HEAD>

(3) Recall the original page when the page is passed a parameter: href= "* * * *. Aspx?random () "


1. Cancel Cache

(2) Client cancellation

<meta http-equiv= "Expires" content= "0" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Pragma" content= "No-cache" >

(3) End-of-service device cancellation:

Server-side:
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays (-1);
Response.Cache.SetExpires (DateTime.Now.AddDays (-1));
Response.Expires = 0;
Response.CacheControl = "No-cache";
Response.Cache.SetNoStore ();

Inside Global:
protected void Application_BeginRequest (Object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetNoStore ();
}
<%@ OutPutCache location= "None"%>

Page base class:
public class Pagebase:page
{
Public pagebase () {}

protected override OnLoad (EventArgs e) {
Response.Cache.SetNoStore ();
Base. OnLoad ();
}
}

The simplest way to:-)
Learn csdn this forum, after the URL randomly add some useless parameters, such as:
Http://xxx/xxx/xxx.jpg?p=xxx

IE uses URLs to control the cache, which solves the

(4) Web. config can be set.

(1) What is the difference between client-side caching and the cache object we often use in code, and when we use only client-side caching, does he have any effect on the cache we use in our code?

Two completely different things, the cache object is for you to buffer things with, the advantage is that it will automatically clean out the outdated things. Client-side caching is a specification for HTTP, which is used to cache Web pages on clients, sometimes we need client-side caching to improve browsing speed and reduce the burden on the server, but sometimes we need to disable caching on the client side to prevent clients from seeing outdated information

(2) How to remove the value from the cache when the client browser is closed. When the user is normal logoff can be done, but if the user is directly close the browser to how to implement it?

<body onbeforeunload= "window.open (' clear.aspx ', ', ' top=4000 ')" >

(3) 1. Page.cache,context.cache,httpruntime.cache whether the same Cache object is referenced.

2. What is the difference between them?

3. What are their use cases?

They refer to the same object, which, in the course of a request, Page.cache and HttpContext.Current.Cache are effective, as for the 2 differences, is generally determined by the place you call, if in the page, then with Page.cache, if in Global.asax or own function, then use the latter

But if you need to access an event, such as a timer-based handler, because it is not HttpContext, then use Httpruntime.cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.