You can cache a file or a group of files on the page and set dependencies. However, when a file is changed, the cache becomes invalid.
Aspx is written in the header
<% @ Outputcache varybyparam = "NONE" Duration = "9999" %>
The call time can be used to determine whether to cache
<% = Datetime. Now. tostring ("T") %>
Protected void page_load (Object sender, eventargs E)
{
Response. addfiledependency (mappath ("Luca. xml "));
}
Bind XML with gridview
If the modified XML cache is invalid
Another programming method is to set cache failure.
If a page displays jobs data, the page sets the cache. When I add data to another page, I will remove the data cache that displays jobs.
Add a page
<% @ Outputcache varybyparam = "NONE" Duration = "9999" %>
This page is called jobs. aspx.
Get the value of jobs
I will not write it if I bind it with the gridview.
Add a link to the add jobs page
<A href = "addjobs. aspx"> addjobs. aspx </a>
On the addjobs page
After the add operation is completed, write as follows:Code
string SQL = "insert into jobs values ('luca', 30,50)";
sqlcommand cmd = new sqlcommand (SQL, con);
con. open ();
cmd. executenonquery ();
con. close (); httpresponse. removeoutputcacheitem (page. resolveurl ("~ /Jobs. aspx ");
response. Redirect ("~ /Jobs. aspx ");
}
There is another situation.
If multiple pages call jobs data and the data is cached
The above httpresponse. removeoutputcacheitem can only remove one page at a time. We need to use the cache
In jobs. aspx
Protected void page_load (Object sender, eventargs E)
{
Cache. insert ("Jobs", datetime. Now );
Response. addcacheitemdependency ("Jobs ");
}
Then, after adding an operation in addjobs
Cache. Remove ("Jobs ");
OK.
If another page such as jobsdetails. aspx
Jobs data is also cached.
Also, you only need to write in page_load.
Response. addcacheitemdependency ("Jobs ");
The cache will also be lost.